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

Method test_junit_duration_report

testing/test_junitxml.py:318–349  ·  view source on GitHub ↗
(
        self,
        pytester: Pytester,
        monkeypatch: MonkeyPatch,
        duration_report: str,
        run_and_parse: RunAndParse,
    )

Source from the content-addressed store, hash-verified

316
317 @pytest.mark.parametrize("duration_report", ["call", "total"])
318 def test_junit_duration_report(
319 self,
320 pytester: Pytester,
321 monkeypatch: MonkeyPatch,
322 duration_report: str,
323 run_and_parse: RunAndParse,
324 ) -> None:
325 # mock LogXML.node_reporter so it always sets a known duration to each test report object
326 original_node_reporter = LogXML.node_reporter
327
328 def node_reporter_wrapper(s: Any, report: TestReport) -> Any:
329 report.duration = 1.0
330 reporter = original_node_reporter(s, report)
331 return reporter
332
333 monkeypatch.setattr(LogXML, "node_reporter", node_reporter_wrapper)
334
335 pytester.makepyfile(
336 """
337 def test_foo():
338 pass
339 """
340 )
341 _result, dom = run_and_parse("-o", f"junit_duration_report={duration_report}")
342 node = dom.get_first_by_tag("testsuite")
343 tnode = node.get_first_by_tag("testcase")
344 val = float(tnode["time"])
345 if duration_report == "total":
346 assert val == 3.0
347 else:
348 assert duration_report == "call"
349 assert val == 1.0
350
351 @parametrize_families
352 def test_setup_error(

Callers

nothing calls this directly

Calls 4

run_and_parseFunction · 0.85
setattrMethod · 0.80
get_first_by_tagMethod · 0.80
makepyfileMethod · 0.45

Tested by

no test coverage detected