Skip to content

Commit 0b51f91

Browse files
committed
Use PytestWarning and tweak the message
1 parent 425dc24 commit 0b51f91

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/_pytest/fixtures.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
from _pytest.scope import HIGH_SCOPES
7272
from _pytest.scope import Scope
7373
from _pytest.warning_types import PytestRemovedIn9Warning
74+
from _pytest.warning_types import PytestWarning
7475

7576

7677
if sys.version_info < (3, 11):
@@ -1564,7 +1565,9 @@ def _getusefixturesnames(self, node: nodes.Item) -> Iterator[str]:
15641565
"""Return the names of usefixtures fixtures applicable to node."""
15651566
for marker_node, mark in node.iter_markers_with_node(name="usefixtures"):
15661567
if not mark.args:
1567-
marker_node.warn(Warning("usefixtures() is empty, so it has no effect"))
1568+
marker_node.warn(
1569+
PytestWarning("usefixtures() without arguments has no effect")
1570+
)
15681571
yield from mark.args
15691572

15701573
def getfixtureclosure(

testing/python/fixtures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,7 @@ def test_two(self):
14361436
reprec.assertoutcome(passed=2)
14371437

14381438
def test_empty_usefixtures_marker(self, pytester: Pytester) -> None:
1439+
"""Empty usefixtures() marker issues a warning (#12439)."""
14391440
pytester.makepyfile(
14401441
"""
14411442
import pytest
@@ -1447,7 +1448,7 @@ def test_one():
14471448
)
14481449
result = pytester.runpytest()
14491450
result.stdout.fnmatch_lines(
1450-
"*Warning: usefixtures() is empty, so it has no effect"
1451+
"*PytestWarning: usefixtures() without arguments has no effect"
14511452
)
14521453

14531454
def test_usefixtures_ini(self, pytester: Pytester) -> None:

0 commit comments

Comments
 (0)