MCPcopy
hub / github.com/pytest-dev/pytest / RunAndParse

Class RunAndParse

testing/test_junitxml.py:36–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35
36class RunAndParse:
37 def __init__(self, pytester: Pytester, schema: xmlschema.XMLSchema) -> None:
38 self.pytester = pytester
39 self.schema = schema
40
41 def __call__(
42 self,
43 *args: str | os.PathLike[str],
44 family: str | None = "xunit1",
45 suite_name: str = "pytest",
46 ) -> tuple[RunResult, DomDocument]:
47 if family:
48 args = ("-o", "junit_family=" + family, *args)
49 xml_path = self.pytester.path.joinpath("junit.xml")
50 result = self.pytester.runpytest(f"--junitxml={xml_path}", *args)
51 if family == "xunit2":
52 with xml_path.open(encoding="utf-8") as f:
53 self.schema.validate(f)
54 xmldoc = minidom.parse(str(xml_path))
55 # Ensure the tests attribute of the ``<testsuite>`` element
56 # always matches the number of ``<testcase>`` elements (#3580).
57 doc = DomDocument(xmldoc)
58 testcase_nodes = doc.find_by_tag("testcase")
59 test_suite_node = doc.get_first_by_tag("testsuite")
60 test_suite_node.assert_attr(name=suite_name, tests=len(testcase_nodes))
61 return result, doc
62
63
64@pytest.fixture

Callers 1

run_and_parseFunction · 0.85

Calls

no outgoing calls

Tested by 1

run_and_parseFunction · 0.68