From c3e2b11a62234c283b4ed4a7bfe5edf7eb6f3d4d Mon Sep 17 00:00:00 2001 From: Arvin Firouzi Date: Thu, 9 Jul 2020 22:10:32 +0200 Subject: [PATCH] Fix reported location of skip when --runxfail is used (#7432) Co-authored-by: Arvin Firouzi <427014@student.fontys.nl> --- changelog/7392.bugfix.rst | 1 + src/_pytest/skipping.py | 3 ++- testing/test_skipping.py | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 changelog/7392.bugfix.rst diff --git a/changelog/7392.bugfix.rst b/changelog/7392.bugfix.rst new file mode 100644 index 000000000..48cd949fa --- /dev/null +++ b/changelog/7392.bugfix.rst @@ -0,0 +1 @@ +Fix the reported location of tests skipped with ``@pytest.mark.skip`` when ``--runxfail`` is used. diff --git a/src/_pytest/skipping.py b/src/_pytest/skipping.py index a72bdaabf..dca2466c4 100644 --- a/src/_pytest/skipping.py +++ b/src/_pytest/skipping.py @@ -291,7 +291,8 @@ def pytest_runtest_makereport(item: Item, call: CallInfo[None]): else: rep.outcome = "passed" rep.wasxfail = xfailed.reason - elif ( + + if ( item._store.get(skipped_by_mark_key, True) and rep.skipped and type(rep.longrepr) is tuple diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 0b1c0b49b..8fceb37aa 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -235,6 +235,31 @@ class TestXFail: ["*def test_func():*", "*assert 0*", "*1 failed*1 pass*"] ) + @pytest.mark.parametrize( + "test_input,expected", + [ + ( + ["-rs"], + ["SKIPPED [1] test_sample.py:2: unconditional skip", "*1 skipped*"], + ), + ( + ["-rs", "--runxfail"], + ["SKIPPED [1] test_sample.py:2: unconditional skip", "*1 skipped*"], + ), + ], + ) + def test_xfail_run_with_skip_mark(self, testdir, test_input, expected): + testdir.makepyfile( + test_sample=""" + import pytest + @pytest.mark.skip + def test_skip_location() -> None: + assert 0 + """ + ) + result = testdir.runpytest(*test_input) + result.stdout.fnmatch_lines(expected) + def test_xfail_evalfalse_but_fails(self, testdir): item = testdir.getitem( """