File tree 3 files changed +16
-13
lines changed
3 files changed +16
-13
lines changed Original file line number Diff line number Diff line change
1
+ If a test is skipped from inside an :ref: `xunit setup fixture <classic xunit >`, the test summary now shows the test location instead of the fixture location.
Original file line number Diff line number Diff line change @@ -1162,9 +1162,10 @@ def pytest_fixture_setup(
1162
1162
try :
1163
1163
result = call_fixture_func (fixturefunc , request , kwargs )
1164
1164
except TEST_OUTCOME as e :
1165
- if isinstance (e , skip .Exception ) and not fixturefunc .__name__ .startswith (
1166
- "xunit_setup"
1167
- ):
1165
+ if isinstance (e , skip .Exception ):
1166
+ # The test requested a fixture which caused a skip.
1167
+ # Don't show the fixture as the skip location, as then the user
1168
+ # wouldn't know which test skipped.
1168
1169
e ._use_item_location = True
1169
1170
fixturedef .cached_result = (None , my_cache_key , e )
1170
1171
raise
Original file line number Diff line number Diff line change @@ -989,33 +989,34 @@ def test_skipped_reasons_functional(pytester: Pytester) -> None:
989
989
pytester .makepyfile (
990
990
test_one = """
991
991
import pytest
992
- from conftest import doskip
992
+ from helpers import doskip
993
993
994
- def setup_function(func):
995
- doskip()
994
+ def setup_function(func): # LINE 4
995
+ doskip("setup function" )
996
996
997
997
def test_func():
998
998
pass
999
999
1000
- class TestClass(object) :
1000
+ class TestClass:
1001
1001
def test_method(self):
1002
- doskip()
1002
+ doskip("test method" )
1003
1003
1004
- @pytest.mark.skip("via_decorator")
1004
+ @pytest.mark.skip("via_decorator") # LINE 14
1005
1005
def test_deco(self):
1006
1006
assert 0
1007
1007
""" ,
1008
- conftest = """
1008
+ helpers = """
1009
1009
import pytest, sys
1010
- def doskip():
1010
+ def doskip(reason ):
1011
1011
assert sys._getframe().f_lineno == 3
1012
- pytest.skip('test')
1012
+ pytest.skip(reason) # LINE 4
1013
1013
""" ,
1014
1014
)
1015
1015
result = pytester .runpytest ("-rs" )
1016
1016
result .stdout .fnmatch_lines_random (
1017
1017
[
1018
- "SKIPPED [[]2[]] conftest.py:4: test" ,
1018
+ "SKIPPED [[]1[]] test_one.py:7: setup function" ,
1019
+ "SKIPPED [[]1[]] helpers.py:4: test method" ,
1019
1020
"SKIPPED [[]1[]] test_one.py:14: via_decorator" ,
1020
1021
]
1021
1022
)
You can’t perform that action at this time.
0 commit comments