From 8fa57c8384818efcc83af604f0ccfc2620dd111c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 21 Jan 2020 11:30:32 +0100 Subject: [PATCH] tests: improve test for `nose.raises` This should probably get transferred into a `pytest.fail` really, but tests/documents the current behavior. --- testing/test_nose.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/testing/test_nose.py b/testing/test_nose.py index 469c127af..15be7b73a 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -377,15 +377,45 @@ def test_skip_test_with_unicode(testdir): result.stdout.fnmatch_lines(["* 1 skipped *"]) -def test_issue_6517(testdir): +def test_raises(testdir): testdir.makepyfile( """ from nose.tools import raises @raises(RuntimeError) - def test_fail_without_tcp(): + def test_raises_runtimeerror(): raise RuntimeError + + @raises(Exception) + def test_raises_baseexception_not_caught(): + raise BaseException + + @raises(BaseException) + def test_raises_baseexception_caught(): + raise BaseException """ ) result = testdir.runpytest() - result.stdout.fnmatch_lines(["* 1 passed *"]) + result.stdout.fnmatch_lines( + [ + "*= FAILURES =*", + "*_ test_raises_baseexception_not_caught _*", + "", + "arg = (), kw = {}", + "", + " def newfunc(*arg, **kw):", + " try:", + "> func(*arg, **kw)", + "", + "*/nose/*: ", + "_ _ *", + "", + " @raises(Exception)", + " def test_raises_baseexception_not_caught():", + "> raise BaseException", + "E BaseException", + "", + "test_raises.py:9: BaseException", + "* 1 failed, 2 passed *", + ] + )