Skip to content

Commit

Permalink
Merge pull request #10638 from pytest-dev/backport-10607-to-7.2.x
Browse files Browse the repository at this point in the history
[7.2.x] Mitigate directory creation race condition
  • Loading branch information
nicoddemus authored Jan 6, 2023
2 parents 08d0dd0 + a6f85a0 commit 211d08e
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 211d08e

Please sign in to comment.