(
self,
pytester: Pytester,
junit_logging,
run_and_parse: RunAndParse,
xunit_family,
)
| 499 | ) |
| 500 | @parametrize_families |
| 501 | def test_failure_function( |
| 502 | self, |
| 503 | pytester: Pytester, |
| 504 | junit_logging, |
| 505 | run_and_parse: RunAndParse, |
| 506 | xunit_family, |
| 507 | ) -> None: |
| 508 | pytester.makepyfile( |
| 509 | """ |
| 510 | import logging |
| 511 | import sys |
| 512 | |
| 513 | def test_fail(): |
| 514 | print("hello-stdout") |
| 515 | sys.stderr.write("hello-stderr\\n") |
| 516 | logging.info('info msg') |
| 517 | logging.warning('warning msg') |
| 518 | raise ValueError(42) |
| 519 | """ |
| 520 | ) |
| 521 | |
| 522 | result, dom = run_and_parse( |
| 523 | "-o", "junit_logging=%s" % junit_logging, family=xunit_family |
| 524 | ) |
| 525 | assert result.ret, "Expected ret > 0" |
| 526 | node = dom.find_first_by_tag("testsuite") |
| 527 | node.assert_attr(failures=1, tests=1) |
| 528 | tnode = node.find_first_by_tag("testcase") |
| 529 | tnode.assert_attr(classname="test_failure_function", name="test_fail") |
| 530 | fnode = tnode.find_first_by_tag("failure") |
| 531 | fnode.assert_attr(message="ValueError: 42") |
| 532 | assert "ValueError" in fnode.toxml(), "ValueError not included" |
| 533 | |
| 534 | if junit_logging in ["log", "all"]: |
| 535 | logdata = tnode.find_first_by_tag("system-out") |
| 536 | log_xml = logdata.toxml() |
| 537 | assert logdata.tag == "system-out", "Expected tag: system-out" |
| 538 | assert "info msg" not in log_xml, "Unexpected INFO message" |
| 539 | assert "warning msg" in log_xml, "Missing WARN message" |
| 540 | if junit_logging in ["system-out", "out-err", "all"]: |
| 541 | systemout = tnode.find_first_by_tag("system-out") |
| 542 | systemout_xml = systemout.toxml() |
| 543 | assert systemout.tag == "system-out", "Expected tag: system-out" |
| 544 | assert "info msg" not in systemout_xml, "INFO message found in system-out" |
| 545 | assert ( |
| 546 | "hello-stdout" in systemout_xml |
| 547 | ), "Missing 'hello-stdout' in system-out" |
| 548 | if junit_logging in ["system-err", "out-err", "all"]: |
| 549 | systemerr = tnode.find_first_by_tag("system-err") |
| 550 | systemerr_xml = systemerr.toxml() |
| 551 | assert systemerr.tag == "system-err", "Expected tag: system-err" |
| 552 | assert "info msg" not in systemerr_xml, "INFO message found in system-err" |
| 553 | assert ( |
| 554 | "hello-stderr" in systemerr_xml |
| 555 | ), "Missing 'hello-stderr' in system-err" |
| 556 | assert ( |
| 557 | "warning msg" not in systemerr_xml |
| 558 | ), "WARN message found in system-err" |
nothing calls this directly
no test coverage detected