Skip to content

Commit a6f85a0

Browse files
Kadinopytestbot
authored andcommitted
[7.2.x] Mitigate directory creation race condition
1 parent 08d0dd0 commit a6f85a0

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

changelog/10607.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a race condition when creating junitxml reports, which could occur when multiple instances of pytest execute in parallel.

src/_pytest/junitxml.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ def pytest_sessionstart(self) -> None:
645645

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

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

0 commit comments

Comments
 (0)