Skip to content

Skip reports refer to pytest code instead of original test functions #789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
- fix issue735: assertion failures on debug versions of Python 3.4+
Thanks Benjamin Peterson.

- fix issue114: skipif marker reports to internal skipping plugin;
Thanks Floris Bruynooghe for reporting and Bruno Oliveira for the PR.

- fix issue748: unittest.SkipTest reports to internal pytest unittest plugin.
Thanks Thomas De Schampheleire for reporting and Bruno Oliveira for the PR.

2.7.1 (compared to 2.7.0)
-----------------------------

Expand Down
9 changes: 9 additions & 0 deletions _pytest/skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def getexplanation(self):
def pytest_runtest_setup(item):
evalskip = MarkEvaluator(item, 'skipif')
if evalskip.istrue():
item._evalskip = evalskip
pytest.skip(evalskip.getexplanation())
item._evalxfail = MarkEvaluator(item, 'xfail')
check_xfail_no_run(item)
Expand All @@ -156,6 +157,7 @@ def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
evalxfail = getattr(item, '_evalxfail', None)
evalskip = getattr(item, '_evalskip', None)
# unitttest special case, see setting of _unexpectedsuccess
if hasattr(item, '_unexpectedsuccess') and rep.when == "call":
# we need to translate into how pytest encodes xpass
Expand All @@ -177,6 +179,13 @@ def pytest_runtest_makereport(item, call):
elif call.when == "call":
rep.outcome = "failed" # xpass outcome
rep.wasxfail = evalxfail.getexplanation()
elif evalskip is not None and rep.skipped and type(rep.longrepr) is tuple:
# skipped by mark.skipif; change the location of the failure
# to point to the item definition, otherwise it will display
# the location of where the skip exception was raised within pytest
filename, line, reason = rep.longrepr
filename, line = item.location[:2]
rep.longrepr = filename, line, reason

# called by terminalreporter progress reporting
def pytest_report_teststatus(report):
Expand Down
3 changes: 3 additions & 0 deletions _pytest/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# for transfering markers
from _pytest.python import transfer_markers
from _pytest.skipping import MarkEvaluator


def pytest_pycollect_makeitem(collector, name, obj):
Expand Down Expand Up @@ -113,6 +114,8 @@ def addSkip(self, testcase, reason):
try:
pytest.skip(reason)
except pytest.skip.Exception:
self._evalskip = MarkEvaluator(self, 'SkipTest')
self._evalskip.result = True
self._addexcinfo(sys.exc_info())

def addExpectedFailure(self, testcase, rawexcinfo, reason=""):
Expand Down
4 changes: 2 additions & 2 deletions testing/test_skipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,15 @@ def test_func():


def test_skipif_reporting(self, testdir):
p = testdir.makepyfile("""
p = testdir.makepyfile(test_foo="""
import pytest
@pytest.mark.skipif("hasattr(sys, 'platform')")
def test_that():
assert 0
""")
result = testdir.runpytest(p, '-s', '-rs')
result.stdout.fnmatch_lines([
"*SKIP*1*platform*",
"*SKIP*1*test_foo.py*platform*",
"*1 skipped*"
])
assert result.ret == 0
Expand Down
13 changes: 13 additions & 0 deletions testing/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,17 @@ def test_func(self):
reprec = testdir.inline_run()
reprec.assertoutcome(failed=1)

@pytest.mark.skipif("sys.version_info < (2,7)")
def test_unittest_raise_skip_issue748(testdir):
testdir.makepyfile(test_foo="""
import unittest

class MyTestCase(unittest.TestCase):
def test_one(self):
raise unittest.SkipTest('skipping due to reasons')
""")
result = testdir.runpytest("-v", '-rs')
result.stdout.fnmatch_lines("""
*SKIP*[1]*test_foo.py*skipping due to reasons*
*1 skipped*
""")