MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_raises

Function test_raises

testing/test_nose.py:435–479  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

433
434
435def test_raises(pytester: Pytester) -> None:
436 pytester.makepyfile(
437 """
438 from nose.tools import raises
439
440 @raises(RuntimeError)
441 def test_raises_runtimeerror():
442 raise RuntimeError
443
444 @raises(Exception)
445 def test_raises_baseexception_not_caught():
446 raise BaseException
447
448 @raises(BaseException)
449 def test_raises_baseexception_caught():
450 raise BaseException
451 """
452 )
453 result = pytester.runpytest("-vv")
454 result.stdout.fnmatch_lines(
455 [
456 "test_raises.py::test_raises_runtimeerror PASSED*",
457 "test_raises.py::test_raises_baseexception_not_caught FAILED*",
458 "test_raises.py::test_raises_baseexception_caught PASSED*",
459 "*= FAILURES =*",
460 "*_ test_raises_baseexception_not_caught _*",
461 "",
462 "arg = (), kw = {}",
463 "",
464 " def newfunc(*arg, **kw):",
465 " try:",
466 "> func(*arg, **kw)",
467 "",
468 "*/nose/*: ",
469 "_ _ *",
470 "",
471 " @raises(Exception)",
472 " def test_raises_baseexception_not_caught():",
473 "> raise BaseException",
474 "E BaseException",
475 "",
476 "test_raises.py:9: BaseException",
477 "* 1 failed, 2 passed *",
478 ]
479 )
480
481
482def test_nose_setup_skipped_if_non_callable(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected