merge pull request #27: correctly handle nose.SkipTest during collection. Thanks
Antonio Cuni, Ronny Pfannschmidt. I did a few tweaks to the test and the activation (depending on if unittest is imported at all).
This commit is contained in:
commit
ca7c1f5d8e
|
@ -1,6 +1,9 @@
|
||||||
Changes between 2.3.5 and 2.4.DEV
|
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
|
- new monkeypatch.replace() to avoid imports and provide a shorter
|
||||||
invocation for patching out classes/functions from modules:
|
invocation for patching out classes/functions from modules:
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ except ImportError:
|
||||||
from UserDict import DictMixin as MappingMixin
|
from UserDict import DictMixin as MappingMixin
|
||||||
|
|
||||||
from _pytest.mark import MarkInfo
|
from _pytest.mark import MarkInfo
|
||||||
|
import _pytest.runner
|
||||||
|
|
||||||
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
|
tracebackcutdir = py.path.local(_pytest.__file__).dirpath()
|
||||||
|
|
||||||
|
@ -368,6 +369,11 @@ class Collector(Node):
|
||||||
""" Collector instances create children through collect()
|
""" Collector instances create children through collect()
|
||||||
and thus iteratively build a tree.
|
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):
|
class CollectError(Exception):
|
||||||
""" an error during collection, contains a custom message. """
|
""" an error during collection, contains a custom message. """
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@ def teardown_nose(item):
|
||||||
# del item.parent._nosegensetup
|
# del item.parent._nosegensetup
|
||||||
|
|
||||||
def pytest_make_collect_report(collector):
|
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):
|
if isinstance(collector, pytest.Generator):
|
||||||
call_optional(collector.obj, 'setup')
|
call_optional(collector.obj, 'setup')
|
||||||
|
|
||||||
|
|
|
@ -604,9 +604,10 @@ class ReportRecorder(object):
|
||||||
passed = []
|
passed = []
|
||||||
skipped = []
|
skipped = []
|
||||||
failed = []
|
failed = []
|
||||||
for rep in self.getreports("pytest_runtest_logreport"):
|
for rep in self.getreports(
|
||||||
|
"pytest_collectreport pytest_runtest_logreport"):
|
||||||
if rep.passed:
|
if rep.passed:
|
||||||
if rep.when == "call":
|
if getattr(rep, "when", None) == "call":
|
||||||
passed.append(rep)
|
passed.append(rep)
|
||||||
elif rep.skipped:
|
elif rep.skipped:
|
||||||
skipped.append(rep)
|
skipped.append(rep)
|
||||||
|
|
|
@ -258,7 +258,7 @@ def pytest_make_collect_report(collector):
|
||||||
if not call.excinfo:
|
if not call.excinfo:
|
||||||
outcome = "passed"
|
outcome = "passed"
|
||||||
else:
|
else:
|
||||||
if call.excinfo.errisinstance(py.test.skip.Exception):
|
if call.excinfo.errisinstance(collector.skip_exceptions):
|
||||||
outcome = "skipped"
|
outcome = "skipped"
|
||||||
r = collector._repr_failure_py(call.excinfo, "line").reprcrash
|
r = collector._repr_failure_py(call.excinfo, "line").reprcrash
|
||||||
longrepr = (str(r.path), r.lineno, r.message)
|
longrepr = (str(r.path), r.lineno, r.message)
|
||||||
|
|
|
@ -327,6 +327,15 @@ def test_setup_teardown_linking_issue265(testdir):
|
||||||
"""Undoes the setup."""
|
"""Undoes the setup."""
|
||||||
raise Exception("should not call teardown for skipped tests")
|
raise Exception("should not call teardown for skipped tests")
|
||||||
''')
|
''')
|
||||||
|
reprec = testdir.inline_run()
|
||||||
|
reprec.assertoutcome(passed=1, skipped=1)
|
||||||
|
|
||||||
result = testdir.runpytest()
|
def test_SkipTest_during_collection(testdir):
|
||||||
result.stdout.fnmatch_lines("*1 skipped*")
|
testdir.makepyfile("""
|
||||||
|
import nose
|
||||||
|
raise nose.SkipTest("during collection")
|
||||||
|
def test_failing():
|
||||||
|
assert False
|
||||||
|
""")
|
||||||
|
reprec = testdir.inline_run()
|
||||||
|
reprec.assertoutcome(skipped=1)
|
||||||
|
|
Loading…
Reference in New Issue