Skip to content

Commit

Permalink
[7.2.x] Mitigate directory creation race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadino authored and pytestbot committed Jan 6, 2023
1 parent 08d0dd0 commit a6f85a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/10607.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a race condition when creating junitxml reports, which could occur when multiple instances of pytest execute in parallel.
4 changes: 2 additions & 2 deletions src/_pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ def pytest_sessionstart(self) -> None:

def pytest_sessionfinish(self) -> None:
dirname = os.path.dirname(os.path.abspath(self.logfile))
if not os.path.isdir(dirname):
os.makedirs(dirname)
# exist_ok avoids filesystem race conditions between checking path existence and requesting creation
os.makedirs(dirname, exist_ok=True)

with open(self.logfile, "w", encoding="utf-8") as logfile:
suite_stop_time = timing.time()
Expand Down

0 comments on commit a6f85a0

Please sign in to comment.