correctly handle nose.SkipTest during collection

This commit is contained in:
Antonio Cuni 2013-03-14 16:10:33 +01:00
parent 5ba2a7f628
commit 37c47155e0
4 changed files with 24 additions and 1 deletions

View File

@ -347,6 +347,18 @@ class Collector(Node):
""" Collector instances create children through collect()
and thus iteratively build a tree.
"""
_skip_exceptions = None
@property
def skip_exceptions(self):
if self._skip_exceptions is None:
return (py.test.skip.Exception,)
return self._skip_exceptions
@skip_exceptions.setter
def skip_exceptions(self, value):
self._skip_exceptions = value
class CollectError(Exception):
""" an error during collection, contains a custom message. """

View File

@ -38,6 +38,8 @@ def pytest_runtest_teardown(item):
# del item.parent._nosegensetup
def pytest_make_collect_report(collector):
SkipTest = py.std.unittest.SkipTest
collector.skip_exceptions += (SkipTest,)
if isinstance(collector, pytest.Generator):
call_optional(collector.obj, 'setup')

View File

@ -249,7 +249,7 @@ def pytest_make_collect_report(collector):
if not call.excinfo:
outcome = "passed"
else:
if call.excinfo.errisinstance(py.test.skip.Exception):
if call.excinfo.errisinstance(collector.skip_exceptions):
outcome = "skipped"
r = collector._repr_failure_py(call.excinfo, "line").reprcrash
longrepr = (str(r.path), r.lineno, r.message)

View File

@ -305,3 +305,12 @@ def test_apiwrapper_problem_issue260(testdir):
result.stdout.fnmatch_lines("*1 passed*")
def test_SkipTest_during_collection(testdir):
testdir.makepyfile("""
import nose
raise nose.SkipTest("during collection")
def test_failing():
assert False
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines("*1 skipped*")