Skip to content

Add support for using the same fixture twice in a function #5896

Closed
@torfsen

Description

@torfsen

I often end up using the same fixture twice (or even more times) in the same function, for example to get two temporary directories using tmp_path. As far as a I know, this is currently only possible by manually creating a copy of the fixture:

tmp_path2 = tmp_path

def test_foo(tmp_path, tmp_path2):
    assert something

I would love to see native support for this, and I think keyword arguments would be a nice way to achieve this from the user's perspective:

def test_foo(input_path=tmp_path, output_path=tmp_path):
    assert something

This would give the user two (or more) independent instances of the fixture.

I don't know enough about the pytest internals to judge how hard this would be to implement, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions