Open log file in context manager (#8659)
Co-authored-by: Zachary Kneupper <zacharykneupper@Zacharys-MBP.lan>
This commit is contained in:
parent
822624c252
commit
b4cd14aae3
|
@ -648,39 +648,39 @@ class LogXML:
|
||||||
dirname = os.path.dirname(os.path.abspath(self.logfile))
|
dirname = os.path.dirname(os.path.abspath(self.logfile))
|
||||||
if not os.path.isdir(dirname):
|
if not os.path.isdir(dirname):
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
logfile = open(self.logfile, "w", encoding="utf-8")
|
|
||||||
suite_stop_time = timing.time()
|
|
||||||
suite_time_delta = suite_stop_time - self.suite_start_time
|
|
||||||
|
|
||||||
numtests = (
|
with open(self.logfile, "w", encoding="utf-8") as logfile:
|
||||||
self.stats["passed"]
|
suite_stop_time = timing.time()
|
||||||
+ self.stats["failure"]
|
suite_time_delta = suite_stop_time - self.suite_start_time
|
||||||
+ self.stats["skipped"]
|
|
||||||
+ self.stats["error"]
|
|
||||||
- self.cnt_double_fail_tests
|
|
||||||
)
|
|
||||||
logfile.write('<?xml version="1.0" encoding="utf-8"?>')
|
|
||||||
|
|
||||||
suite_node = ET.Element(
|
numtests = (
|
||||||
"testsuite",
|
self.stats["passed"]
|
||||||
name=self.suite_name,
|
+ self.stats["failure"]
|
||||||
errors=str(self.stats["error"]),
|
+ self.stats["skipped"]
|
||||||
failures=str(self.stats["failure"]),
|
+ self.stats["error"]
|
||||||
skipped=str(self.stats["skipped"]),
|
- self.cnt_double_fail_tests
|
||||||
tests=str(numtests),
|
)
|
||||||
time="%.3f" % suite_time_delta,
|
logfile.write('<?xml version="1.0" encoding="utf-8"?>')
|
||||||
timestamp=datetime.fromtimestamp(self.suite_start_time).isoformat(),
|
|
||||||
hostname=platform.node(),
|
suite_node = ET.Element(
|
||||||
)
|
"testsuite",
|
||||||
global_properties = self._get_global_properties_node()
|
name=self.suite_name,
|
||||||
if global_properties is not None:
|
errors=str(self.stats["error"]),
|
||||||
suite_node.append(global_properties)
|
failures=str(self.stats["failure"]),
|
||||||
for node_reporter in self.node_reporters_ordered:
|
skipped=str(self.stats["skipped"]),
|
||||||
suite_node.append(node_reporter.to_xml())
|
tests=str(numtests),
|
||||||
testsuites = ET.Element("testsuites")
|
time="%.3f" % suite_time_delta,
|
||||||
testsuites.append(suite_node)
|
timestamp=datetime.fromtimestamp(self.suite_start_time).isoformat(),
|
||||||
logfile.write(ET.tostring(testsuites, encoding="unicode"))
|
hostname=platform.node(),
|
||||||
logfile.close()
|
)
|
||||||
|
global_properties = self._get_global_properties_node()
|
||||||
|
if global_properties is not None:
|
||||||
|
suite_node.append(global_properties)
|
||||||
|
for node_reporter in self.node_reporters_ordered:
|
||||||
|
suite_node.append(node_reporter.to_xml())
|
||||||
|
testsuites = ET.Element("testsuites")
|
||||||
|
testsuites.append(suite_node)
|
||||||
|
logfile.write(ET.tostring(testsuites, encoding="unicode"))
|
||||||
|
|
||||||
def pytest_terminal_summary(self, terminalreporter: TerminalReporter) -> None:
|
def pytest_terminal_summary(self, terminalreporter: TerminalReporter) -> None:
|
||||||
terminalreporter.write_sep("-", f"generated xml file: {self.logfile}")
|
terminalreporter.write_sep("-", f"generated xml file: {self.logfile}")
|
||||||
|
|
Loading…
Reference in New Issue