diff --git a/CHANGELOG b/CHANGELOG index c70188462..be369bc06 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 2.3.5 and 2.4.DEV ----------------------------------- +- PR27: correctly handle nose.SkipTest during collection. Thanks + Antonio Cuni, Ronny Pfannschmidt. + - new monkeypatch.replace() to avoid imports and provide a shorter invocation for patching out classes/functions from modules: diff --git a/_pytest/main.py b/_pytest/main.py index 2d1152423..cde683b47 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() @@ -368,6 +369,11 @@ class Collector(Node): """ Collector instances create children through collect() and thus iteratively build a tree. """ + + # 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. """ diff --git a/_pytest/nose.py b/_pytest/nose.py index d61dc8a03..89df65348 100644 --- a/_pytest/nose.py +++ b/_pytest/nose.py @@ -40,6 +40,9 @@ def teardown_nose(item): # del item.parent._nosegensetup def pytest_make_collect_report(collector): + if sys.modules.get("unittest"): + SkipTest = py.std.unittest.SkipTest + collector.skip_exceptions += (SkipTest,) if isinstance(collector, pytest.Generator): call_optional(collector.obj, 'setup') diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 41241f570..2b96beef9 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -604,9 +604,10 @@ class ReportRecorder(object): passed = [] skipped = [] failed = [] - for rep in self.getreports("pytest_runtest_logreport"): + for rep in self.getreports( + "pytest_collectreport pytest_runtest_logreport"): if rep.passed: - if rep.when == "call": + if getattr(rep, "when", None) == "call": passed.append(rep) elif rep.skipped: skipped.append(rep) diff --git a/_pytest/runner.py b/_pytest/runner.py index c79690d78..00a725bb9 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -258,7 +258,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 3ecfa9c07..12f9dece3 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -327,6 +327,15 @@ def test_setup_teardown_linking_issue265(testdir): """Undoes the setup.""" raise Exception("should not call teardown for skipped tests") ''') + reprec = testdir.inline_run() + reprec.assertoutcome(passed=1, skipped=1) - result = testdir.runpytest() - result.stdout.fnmatch_lines("*1 skipped*") +def test_SkipTest_during_collection(testdir): + testdir.makepyfile(""" + import nose + raise nose.SkipTest("during collection") + def test_failing(): + assert False + """) + reprec = testdir.inline_run() + reprec.assertoutcome(skipped=1)