Skip to content

Commit

Permalink
Merge pull request #7253 from bluetech/fixture-special-case
Browse files Browse the repository at this point in the history
fixtures: remove special cases when deciding when pytest.fixture() is a direct decoration
  • Loading branch information
bluetech committed Jun 5, 2020
2 parents 4c2703b + 5507752 commit e7c26a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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

0 comments on commit e7c26a9

Please sign in to comment.