Merge pull request #11217 from bluetech/fixtures-skip-xunit-loc
fixtures: show test as skip location if skipped from an xunit setup function
This commit is contained in:
commit
29010d23a6
|
@ -0,0 +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.
|
|
@ -1162,9 +1162,10 @@ def pytest_fixture_setup(
|
||||||
try:
|
try:
|
||||||
result = call_fixture_func(fixturefunc, request, kwargs)
|
result = call_fixture_func(fixturefunc, request, kwargs)
|
||||||
except TEST_OUTCOME as e:
|
except TEST_OUTCOME as e:
|
||||||
if isinstance(e, skip.Exception) and not fixturefunc.__name__.startswith(
|
if isinstance(e, skip.Exception):
|
||||||
"xunit_setup"
|
# The test requested a fixture which caused a skip.
|
||||||
):
|
# Don't show the fixture as the skip location, as then the user
|
||||||
|
# wouldn't know which test skipped.
|
||||||
e._use_item_location = True
|
e._use_item_location = True
|
||||||
fixturedef.cached_result = (None, my_cache_key, e)
|
fixturedef.cached_result = (None, my_cache_key, e)
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -989,33 +989,34 @@ def test_skipped_reasons_functional(pytester: Pytester) -> None:
|
||||||
pytester.makepyfile(
|
pytester.makepyfile(
|
||||||
test_one="""
|
test_one="""
|
||||||
import pytest
|
import pytest
|
||||||
from conftest import doskip
|
from helpers import doskip
|
||||||
|
|
||||||
def setup_function(func):
|
def setup_function(func): # LINE 4
|
||||||
doskip()
|
doskip("setup function")
|
||||||
|
|
||||||
def test_func():
|
def test_func():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class TestClass(object):
|
class TestClass:
|
||||||
def test_method(self):
|
def test_method(self):
|
||||||
doskip()
|
doskip("test method")
|
||||||
|
|
||||||
@pytest.mark.skip("via_decorator")
|
@pytest.mark.skip("via_decorator") # LINE 14
|
||||||
def test_deco(self):
|
def test_deco(self):
|
||||||
assert 0
|
assert 0
|
||||||
""",
|
""",
|
||||||
conftest="""
|
helpers="""
|
||||||
import pytest, sys
|
import pytest, sys
|
||||||
def doskip():
|
def doskip(reason):
|
||||||
assert sys._getframe().f_lineno == 3
|
assert sys._getframe().f_lineno == 3
|
||||||
pytest.skip('test')
|
pytest.skip(reason) # LINE 4
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
result = pytester.runpytest("-rs")
|
result = pytester.runpytest("-rs")
|
||||||
result.stdout.fnmatch_lines_random(
|
result.stdout.fnmatch_lines_random(
|
||||||
[
|
[
|
||||||
"SKIPPED [[]2[]] conftest.py:4: test",
|
"SKIPPED [[]1[]] test_one.py:7: setup function",
|
||||||
|
"SKIPPED [[]1[]] helpers.py:4: test method",
|
||||||
"SKIPPED [[]1[]] test_one.py:14: via_decorator",
|
"SKIPPED [[]1[]] test_one.py:14: via_decorator",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue