(
self,
pytester: Pytester,
junit_logging: str,
run_and_parse: RunAndParse,
xunit_family: str,
)
| 568 | ) |
| 569 | @parametrize_families |
| 570 | def test_failure_function( |
| 571 | self, |
| 572 | pytester: Pytester, |
| 573 | junit_logging: str, |
| 574 | run_and_parse: RunAndParse, |
| 575 | xunit_family: str, |
| 576 | ) -> None: |
| 577 | pytester.makepyfile( |
| 578 | """ |
| 579 | import logging |
| 580 | import sys |
| 581 | |
| 582 | def test_fail(): |
| 583 | print("hello-stdout") |
| 584 | sys.stderr.write("hello-stderr\\n") |
| 585 | logging.info('info msg') |
| 586 | logging.warning('warning msg') |
| 587 | raise ValueError(42) |
| 588 | """ |
| 589 | ) |
| 590 | |
| 591 | result, dom = run_and_parse( |
| 592 | "-o", f"junit_logging={junit_logging}", family=xunit_family |
| 593 | ) |
| 594 | assert result.ret, "Expected ret > 0" |
| 595 | node = dom.get_first_by_tag("testsuite") |
| 596 | node.assert_attr(failures=1, tests=1) |
| 597 | tnode = node.get_first_by_tag("testcase") |
| 598 | tnode.assert_attr(classname="test_failure_function", name="test_fail") |
| 599 | fnode = tnode.get_first_by_tag("failure") |
| 600 | fnode.assert_attr(message="ValueError: 42") |
| 601 | assert "ValueError" in fnode.toxml(), "ValueError not included" |
| 602 | |
| 603 | if junit_logging in ["log", "all"]: |
| 604 | logdata = tnode.get_first_by_tag("system-out") |
| 605 | log_xml = logdata.toxml() |
| 606 | assert logdata.tag == "system-out", "Expected tag: system-out" |
| 607 | assert "info msg" not in log_xml, "Unexpected INFO message" |
| 608 | assert "warning msg" in log_xml, "Missing WARN message" |
| 609 | if junit_logging in ["system-out", "out-err", "all"]: |
| 610 | systemout = tnode.get_first_by_tag("system-out") |
| 611 | systemout_xml = systemout.toxml() |
| 612 | assert systemout.tag == "system-out", "Expected tag: system-out" |
| 613 | assert "info msg" not in systemout_xml, "INFO message found in system-out" |
| 614 | assert "hello-stdout" in systemout_xml, ( |
| 615 | "Missing 'hello-stdout' in system-out" |
| 616 | ) |
| 617 | if junit_logging in ["system-err", "out-err", "all"]: |
| 618 | systemerr = tnode.get_first_by_tag("system-err") |
| 619 | systemerr_xml = systemerr.toxml() |
| 620 | assert systemerr.tag == "system-err", "Expected tag: system-err" |
| 621 | assert "info msg" not in systemerr_xml, "INFO message found in system-err" |
| 622 | assert "hello-stderr" in systemerr_xml, ( |
| 623 | "Missing 'hello-stderr' in system-err" |
| 624 | ) |
| 625 | assert "warning msg" not in systemerr_xml, ( |
| 626 | "WARN message found in system-err" |
| 627 | ) |
nothing calls this directly
no test coverage detected