Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/7253.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When using ``pytest.fixture`` on a function directly, as in ``pytest.fixture(func)``,
if the ``autouse`` or ``params`` arguments are also passed, the function is no longer
ignored, but is marked as a fixture.
14 changes: 8 additions & 6 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,13 +1152,15 @@ def fixture(
if params is not None:
params = list(params)

if fixture_function and params is None and autouse is False:
# direct decoration
return FixtureFunctionMarker(scope, params, autouse, name=name)(
fixture_function
)
fixture_marker = FixtureFunctionMarker(
scope=scope, params=params, autouse=autouse, ids=ids, name=name,
)

# Direct decoration.
if fixture_function:
return fixture_marker(fixture_function)

return FixtureFunctionMarker(scope, params, autouse, ids=ids, name=name)
return fixture_marker


def yield_fixture(
Expand Down