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

Method test_junit_duration_report

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

Source from the content-addressed store, hash-verified

247
248 @pytest.mark.parametrize("duration_report", ["call", "total"])
249 def test_junit_duration_report(
250 self,
251 pytester: Pytester,
252 monkeypatch: MonkeyPatch,
253 duration_report: str,
254 run_and_parse: RunAndParse,
255 ) -> None:
256
257 # mock LogXML.node_reporter so it always sets a known duration to each test report object
258 original_node_reporter = LogXML.node_reporter
259
260 def node_reporter_wrapper(s, report):
261 report.duration = 1.0
262 reporter = original_node_reporter(s, report)
263 return reporter
264
265 monkeypatch.setattr(LogXML, "node_reporter", node_reporter_wrapper)
266
267 pytester.makepyfile(
268 """
269 def test_foo():
270 pass
271 """
272 )
273 result, dom = run_and_parse("-o", f"junit_duration_report={duration_report}")
274 node = dom.find_first_by_tag("testsuite")
275 tnode = node.find_first_by_tag("testcase")
276 val = float(tnode["time"])
277 if duration_report == "total":
278 assert val == 3.0
279 else:
280 assert duration_report == "call"
281 assert val == 1.0
282
283 @parametrize_families
284 def test_setup_error(

Callers

nothing calls this directly

Calls 4

run_and_parseFunction · 0.85
setattrMethod · 0.80
find_first_by_tagMethod · 0.80
makepyfileMethod · 0.45

Tested by

no test coverage detected