Skip to content

Commit

Permalink
Merge pull request #198 from chingc/main
Browse files Browse the repository at this point in the history
Fix #130: Test Results directory in setup fails intermittently
  • Loading branch information
ElSnoMan authored Jun 5, 2021
2 parents a924edb + d320a29 commit 6e9c099
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,19 @@ def test_run(project_root, request) -> str:
# delete /test_results from previous Test Run
shutil.rmtree(test_results_dir, ignore_errors=True)

Path(test_results_dir).mkdir(parents=True, exist_ok=True)
try:
# race condition can occur between checking file existence and
# creating the file when using pytest with multiple workers
Path(test_results_dir).mkdir(parents=True, exist_ok=True)
except FileExistsError:
pass

for test in session.items:
# make the test_result directory for each test
Path(f'{test_results_dir}/{test.name}').mkdir(parents=True, exist_ok=True)
try:
# make the test_result directory for each test
Path(f'{test_results_dir}/{test.name}').mkdir(parents=True, exist_ok=True)
except FileExistsError:
pass

return test_results_dir

Expand Down
14 changes: 11 additions & 3 deletions pylenium/scripts/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,19 @@ def test_run(project_root, request) -> str:
# delete /test_results from previous Test Run
shutil.rmtree(test_results_dir, ignore_errors=True)

Path(test_results_dir).mkdir(parents=True, exist_ok=True)
try:
# race condition can occur between checking file existence and
# creating the file when using pytest with multiple workers
Path(test_results_dir).mkdir(parents=True, exist_ok=True)
except FileExistsError:
pass

for test in session.items:
# make the test_result directory for each test
Path(f'{test_results_dir}/{test.name}').mkdir(parents=True, exist_ok=True)
try:
# make the test_result directory for each test
Path(f'{test_results_dir}/{test.name}').mkdir(parents=True, exist_ok=True)
except FileExistsError:
pass

return test_results_dir

Expand Down

0 comments on commit 6e9c099

Please sign in to comment.