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

Method pytest_sessionfinish

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

Source from the content-addressed store, hash-verified

641 self.suite_start_time = timing.time()
642
643 def pytest_sessionfinish(self) -> None:
644 dirname = os.path.dirname(os.path.abspath(self.logfile))
645 if not os.path.isdir(dirname):
646 os.makedirs(dirname)
647
648 with open(self.logfile, "w", encoding="utf-8") as logfile:
649 suite_stop_time = timing.time()
650 suite_time_delta = suite_stop_time - self.suite_start_time
651
652 numtests = (
653 self.stats["passed"]
654 + self.stats["failure"]
655 + self.stats["skipped"]
656 + self.stats["error"]
657 - self.cnt_double_fail_tests
658 )
659 logfile.write('<?xml version="1.0" encoding="utf-8"?>')
660
661 suite_node = ET.Element(
662 "testsuite",
663 name=self.suite_name,
664 errors=str(self.stats["error"]),
665 failures=str(self.stats["failure"]),
666 skipped=str(self.stats["skipped"]),
667 tests=str(numtests),
668 time="%.3f" % suite_time_delta,
669 timestamp=datetime.fromtimestamp(self.suite_start_time).isoformat(),
670 hostname=platform.node(),
671 )
672 global_properties = self._get_global_properties_node()
673 if global_properties is not None:
674 suite_node.append(global_properties)
675 for node_reporter in self.node_reporters_ordered:
676 suite_node.append(node_reporter.to_xml())
677 testsuites = ET.Element("testsuites")
678 testsuites.append(suite_node)
679 logfile.write(ET.tostring(testsuites, encoding="unicode"))
680
681 def pytest_terminal_summary(self, terminalreporter: TerminalReporter) -> None:
682 terminalreporter.write_sep("-", f"generated xml file: {self.logfile}")

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 6

timeMethod · 0.80
nodeMethod · 0.80
appendMethod · 0.80
to_xmlMethod · 0.80
writeMethod · 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