Skip to content

Commit ce1f728

Browse files
authored
Merge pull request #354 from glogiotatidis/makedirs-exist-ok
Use os.makedirs(exist_ok=True).
2 parents d355f07 + a77171c commit ce1f728

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pytest_html/plugin.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ def create_asset(
223223
os.path.dirname(self.logfile), "assets", asset_file_name
224224
)
225225

226-
if not os.path.exists(os.path.dirname(asset_path)):
227-
os.makedirs(os.path.dirname(asset_path))
226+
os.makedirs(os.path.dirname(asset_path), exist_ok=True)
228227

229228
relative_path = f"assets/{asset_file_name}"
230229

@@ -615,10 +614,9 @@ def _save_report(self, report_content):
615614
dir_name = os.path.dirname(self.logfile)
616615
assets_dir = os.path.join(dir_name, "assets")
617616

618-
if not os.path.exists(dir_name):
619-
os.makedirs(dir_name)
620-
if not self.self_contained and not os.path.exists(assets_dir):
621-
os.makedirs(assets_dir)
617+
os.makedirs(dir_name, exist_ok=True)
618+
if not self.self_contained:
619+
os.makedirs(assets_dir, exist_ok=True)
622620

623621
with open(self.logfile, "w", encoding="utf-8") as f:
624622
f.write(report_content)

0 commit comments

Comments
 (0)