Open log file in context manager (#8659)

Co-authored-by: Zachary Kneupper <zacharykneupper@Zacharys-MBP.lan>
This commit is contained in:
Zack Kneupper 2021-05-11 05:10:01 -04:00 committed by GitHub
parent 822624c252
commit b4cd14aae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 31 deletions

View File

@ -648,7 +648,8 @@ class LogXML:
dirname = os.path.dirname(os.path.abspath(self.logfile))
if not os.path.isdir(dirname):
os.makedirs(dirname)
logfile = open(self.logfile, "w", encoding="utf-8")
with open(self.logfile, "w", encoding="utf-8") as logfile:
suite_stop_time = timing.time()
suite_time_delta = suite_stop_time - self.suite_start_time
@ -680,7 +681,6 @@ class LogXML:
testsuites = ET.Element("testsuites")
testsuites.append(suite_node)
logfile.write(ET.tostring(testsuites, encoding="unicode"))
logfile.close()
def pytest_terminal_summary(self, terminalreporter: TerminalReporter) -> None:
terminalreporter.write_sep("-", f"generated xml file: {self.logfile}")