-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved temporary_data_dir fixture to conftest.py since it is a generic…
… fixture that may be useful to multiple test scripts
- Loading branch information
1 parent
96cbaeb
commit 93cff6d
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def temporary_data_dir(request) -> Path: | ||
""" | ||
Create a temporary directory for test data and delete it after test end. | ||
The temporary directory is created in the working directory and it is | ||
named "temp_test_data_folder". | ||
The fixture uses a finalizer that deletes the temporary directory where | ||
every test data was saved. Therefore every time the user calls tests that | ||
use this fixture (and save data inside the returned directory), at the end | ||
of the test the finalizer deletes this directory. | ||
Parameters | ||
---------- | ||
Returns | ||
------- | ||
Path | ||
Path where every temporary file used by tests is saved. | ||
""" | ||
temp_data_dir = Path(os.getcwd()) / "temp_test_data_folder" | ||
try: | ||
os.mkdir(temp_data_dir) | ||
except FileExistsError: | ||
pass | ||
|
||
def remove_temp_dir_created(): | ||
shutil.rmtree(temp_data_dir) | ||
|
||
request.addfinalizer(remove_temp_dir_created) | ||
return temp_data_dir |