From 37c47155e05303dcffdba821396e3ff6c94d0f5b Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 14 Mar 2013 16:10:33 +0100 Subject: [PATCH] correctly handle nose.SkipTest during collection --- _pytest/main.py | 12 ++++++++++++ _pytest/nose.py | 2 ++ _pytest/runner.py | 2 +- testing/test_nose.py | 9 +++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/_pytest/main.py b/_pytest/main.py index 95b2359bc..bf7e54a91 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -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. """ diff --git a/_pytest/nose.py b/_pytest/nose.py index 3064af039..346a8dd3f 100644 --- a/_pytest/nose.py +++ b/_pytest/nose.py @@ -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') diff --git a/_pytest/runner.py b/_pytest/runner.py index 24abfb76b..5988a3a86 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -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) diff --git a/testing/test_nose.py b/testing/test_nose.py index 487b1bbb0..4b5fb88d2 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -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*")