From 0128f1351ab45b2413555f1e31964bbae95f4e8a Mon Sep 17 00:00:00 2001 From: Devon Rueckner Date: Thu, 18 Apr 2019 18:48:22 -0700 Subject: [PATCH] run pytest using a temp home directory --- .gitignore | 1 + kolibri/conftest.py | 14 ++++++++++++++ pytest.ini | 3 +++ requirements/test.txt | 1 + 4 files changed, 19 insertions(+) create mode 100644 kolibri/conftest.py diff --git a/.gitignore b/.gitignore index 32c01fefa0e..c6a10c2e2a2 100644 --- a/.gitignore +++ b/.gitignore @@ -120,6 +120,7 @@ build_tools/crowdin-cli.jar # Ignore pytest cache directory .pytest_cache/ +.pytest_kolibri_home # ignore source font files *.ttf diff --git a/kolibri/conftest.py b/kolibri/conftest.py new file mode 100644 index 00000000000..666fa073c6c --- /dev/null +++ b/kolibri/conftest.py @@ -0,0 +1,14 @@ +import os +import shutil + +import pytest + +# referenced in pytest.ini +TEMP_KOLIBRI_HOME = "./.pytest_kolibri_home" + + +@pytest.fixture(scope="session", autouse=True) +def global_fixture(): + yield # wait until the test ended + if os.path.exists(TEMP_KOLIBRI_HOME): + shutil.rmtree(TEMP_KOLIBRI_HOME) diff --git a/pytest.ini b/pytest.ini index e2f44abf5ac..fb814f8f029 100644 --- a/pytest.ini +++ b/pytest.ini @@ -6,3 +6,6 @@ django_find_project = false DJANGO_SETTINGS_MODULE = kolibri.deployment.default.settings.test # Settings for pytest-pythonpath python_paths = kolibri/dist +env = + # cleaned up in conftest.py fixture + KOLIBRI_HOME=./.pytest_kolibri_home diff --git a/requirements/test.txt b/requirements/test.txt index 36b1f2d3c81..e3ace977899 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -7,5 +7,6 @@ mixer==6.0.1 pytest==3.7.1 # pyup: < 4.0.0 pytest-cov==2.5.1 pytest-django==3.3.3 +pytest-env==0.6.2 pytest-pythonpath==0.7.2 sh==1.12.14