From 37c47155e05303dcffdba821396e3ff6c94d0f5b Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 14 Mar 2013 16:10:33 +0100 Subject: [PATCH 1/2] 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*") From ba0100e0573c46cf1959344807a962a137d4fd7c Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 14 Mar 2013 16:53:57 +0100 Subject: [PATCH 2/2] (antocuni, ronny around): import directly from _pytest.runner to avoid the usage of @property --- _pytest/main.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/_pytest/main.py b/_pytest/main.py index bf7e54a91..95e3b84b5 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -10,6 +10,7 @@ except ImportError: from UserDict import DictMixin as MappingMixin from _pytest.mark import MarkInfo +import _pytest.runner tracebackcutdir = py.path.local(_pytest.__file__).dirpath() @@ -348,16 +349,9 @@ class Collector(Node): 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 + # the set of exceptions to interpret as "Skip the whole module" during + # collection + skip_exceptions = (_pytest.runner.Skipped,) class CollectError(Exception): """ an error during collection, contains a custom message. """