File tree Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ Daniel Grana
88
88
Daniel Hahler
89
89
Daniel Nuri
90
90
Daniel Sánchez Castelló
91
+ Daniel Valenzuela Zenteno
91
92
Daniel Wandschneider
92
93
Daniele Procida
93
94
Danielle Jenkins
Original file line number Diff line number Diff line change
1
+ If a test is skipped from inside a fixture, the test summary now shows the test location instead of the fixture location.
Original file line number Diff line number Diff line change 58
58
from _pytest .mark import ParameterSet
59
59
from _pytest .mark .structures import MarkDecorator
60
60
from _pytest .outcomes import fail
61
+ from _pytest .outcomes import skip
61
62
from _pytest .outcomes import TEST_OUTCOME
62
63
from _pytest .pathlib import absolutepath
63
64
from _pytest .pathlib import bestrelpath
@@ -1129,6 +1130,10 @@ def pytest_fixture_setup(
1129
1130
except TEST_OUTCOME :
1130
1131
exc_info = sys .exc_info ()
1131
1132
assert exc_info [0 ] is not None
1133
+ if isinstance (
1134
+ exc_info [1 ], skip .Exception
1135
+ ) and not fixturefunc .__name__ .startswith ("xunit_setup" ):
1136
+ exc_info [1 ]._use_item_location = True # type: ignore[attr-defined]
1132
1137
fixturedef .cached_result = (None , my_cache_key , exc_info )
1133
1138
raise
1134
1139
fixturedef .cached_result = (result , my_cache_key , None )
Original file line number Diff line number Diff line change @@ -1439,6 +1439,27 @@ def test_pass():
1439
1439
)
1440
1440
1441
1441
1442
+ def test_skip_from_fixture (pytester : Pytester ) -> None :
1443
+ pytester .makepyfile (
1444
+ ** {
1445
+ "tests/test_1.py" : """
1446
+ import pytest
1447
+ def test_pass(arg):
1448
+ pass
1449
+ @pytest.fixture
1450
+ def arg():
1451
+ condition = True
1452
+ if condition:
1453
+ pytest.skip("Fixture conditional skip")
1454
+ """ ,
1455
+ }
1456
+ )
1457
+ result = pytester .runpytest ("-rs" , "tests/test_1.py" , "--rootdir=tests" )
1458
+ result .stdout .fnmatch_lines (
1459
+ ["SKIPPED [[]1[]] tests/test_1.py:2: Fixture conditional skip" ]
1460
+ )
1461
+
1462
+
1442
1463
def test_skip_using_reason_works_ok (pytester : Pytester ) -> None :
1443
1464
p = pytester .makepyfile (
1444
1465
"""
You can’t perform that action at this time.
0 commit comments