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

Method pytest_sessionfinish

src/_pytest/junitxml.py:647–683  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

645 self.suite_start = timing.Instant()
646
647 def pytest_sessionfinish(self) -> None:
648 dirname = os.path.dirname(os.path.abspath(self.logfile))
649 # exist_ok avoids filesystem race conditions between checking path existence and requesting creation
650 os.makedirs(dirname, exist_ok=True)
651
652 with open(self.logfile, "w", encoding="utf-8") as logfile:
653 duration = self.suite_start.elapsed()
654
655 numtests = (
656 self.stats["passed"]
657 + self.stats["failure"]
658 + self.stats["skipped"]
659 + self.stats["error"]
660 - self.cnt_double_fail_tests
661 )
662 logfile.write('<?xml version="1.0" encoding="utf-8"?>')
663
664 suite_node = ET.Element(
665 "testsuite",
666 name=self.suite_name,
667 errors=str(self.stats["error"]),
668 failures=str(self.stats["failure"]),
669 skipped=str(self.stats["skipped"]),
670 tests=str(numtests),
671 time=f"{duration.seconds:.3f}",
672 timestamp=self.suite_start.as_utc().astimezone().isoformat(),
673 hostname=platform.node(),
674 )
675 global_properties = self._get_global_properties_node()
676 if global_properties is not None:
677 suite_node.append(global_properties)
678 for node_reporter in self.node_reporters_ordered:
679 suite_node.append(node_reporter.to_xml())
680 testsuites = ET.Element("testsuites")
681 testsuites.set("name", "pytest tests")
682 testsuites.append(suite_node)
683 logfile.write(ET.tostring(testsuites, encoding="unicode"))
684
685 def pytest_terminal_summary(
686 self, terminalreporter: TerminalReporter, config: pytest.Config

Callers 6

test_unicode_issue368Function · 0.95
test_global_propertiesFunction · 0.95
test_url_propertyFunction · 0.95
getnodeMethod · 0.45
getpathnodeMethod · 0.45
wrap_sessionFunction · 0.45

Calls 9

dirnameMethod · 0.80
elapsedMethod · 0.80
as_utcMethod · 0.80
appendMethod · 0.80
to_xmlMethod · 0.80
setMethod · 0.80
writeMethod · 0.45
nodeMethod · 0.45

Tested by 5

test_unicode_issue368Function · 0.76
test_global_propertiesFunction · 0.76
test_url_propertyFunction · 0.76
getnodeMethod · 0.36
getpathnodeMethod · 0.36