Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Cornelius Riemenschneider
CrazyMerlyn
Cristian Vera
Cyrus Maden
Daara Shaw
Damian Skrzypczak
Daniel Grana
Daniel Hahler
Expand Down Expand Up @@ -209,6 +210,7 @@ Jeff Rackauckas
Jeff Widman
Jenni Rinker
Jens Tröger
Jiajun Xu
John Eddie Ayson
John Litborn
John Towler
Expand Down
1 change: 1 addition & 0 deletions changelog/12426.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A warning is now issued when :ref:`pytest.mark.usefixtures ref` is used without specifying any fixtures. Previously, empty usefixtures markers were silently ignored.
9 changes: 8 additions & 1 deletion src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
from _pytest.scope import HIGH_SCOPES
from _pytest.scope import Scope
from _pytest.warning_types import PytestRemovedIn9Warning
from _pytest.warning_types import PytestWarning


if sys.version_info < (3, 11):
Expand Down Expand Up @@ -1562,7 +1563,13 @@

def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]:
"""Return the names of usefixtures fixtures applicable to node."""
for mark in node.iter_markers(name="usefixtures"):
for marker_node, mark in node.iter_markers_with_node(name="usefixtures"):
if not mark.args:
marker_node.warn(

Check warning on line 1568 in src/_pytest/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/fixtures.py#L1568

Added line #L1568 was not covered by tests
PytestWarning(
f"usefixtures() in {node.nodeid} without arguments has no effect"
)
)
yield from mark.args

def getfixtureclosure(
Expand Down
1 change: 1 addition & 0 deletions testing/plugins_integration/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ addopts = --strict-markers
asyncio_mode = strict
filterwarnings =
error::pytest.PytestWarning
ignore:usefixtures.* without arguments has no effect:pytest.PytestWarning
ignore:.*.fspath is deprecated and will be replaced by .*.path.*:pytest.PytestDeprecationWarning
17 changes: 17 additions & 0 deletions testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,23 @@ def test_two(self):
reprec = pytester.inline_run()
reprec.assertoutcome(passed=2)

def test_empty_usefixtures_marker(self, pytester: Pytester) -> None:
"""Empty usefixtures() marker issues a warning (#12439)."""
pytester.makepyfile(
"""
import pytest

@pytest.mark.usefixtures()
def test_one():
assert 1 == 1
"""
)
result = pytester.runpytest()
result.stdout.fnmatch_lines(
"*PytestWarning: usefixtures() in test_empty_usefixtures_marker.py::test_one"
" without arguments has no effect"
)

def test_usefixtures_ini(self, pytester: Pytester) -> None:
pytester.makeini(
"""
Expand Down