Skip to content

Commit

Permalink
Use a temp dir for media in test
Browse files Browse the repository at this point in the history
  • Loading branch information
mik3y committed Feb 22, 2020
1 parent d4d2541 commit a438713
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Empty file added pykeg/test/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions pykeg/test/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
import pytest
import tempfile
import logging
import shutil
from django.conf import settings


logger = logging.getLogger('pykeg.test.plugin')
TEMP_DATA_DIR = None


@pytest.hookimpl(tryfirst=True)
def pytest_load_initial_conftests(early_config, parser, args):
global TEMP_DATA_DIR
TEMP_DATA_DIR = tempfile.mkdtemp()
os.environ['KEGBOT_DATA_DIR'] = TEMP_DATA_DIR
logger.info('setting KEGBOT_DATA_DIR to {}'.format(TEMP_DATA_DIR))


@pytest.hookimpl
def pytest_sessionfinish(session, exitstatus):
logger.info('removing KEGBOT_DATA_DIR {}'.format(TEMP_DATA_DIR))
shutil.rmtree(TEMP_DATA_DIR)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ignore=E128,E265,E266,E501,W601
max-line-length=100

[tool:pytest]
addopts = -ra --reuse-db --lfnf=all
addopts = -p pykeg.test.plugin -ra --reuse-db --lfnf=all
testpaths = pykeg/
python_files = tests.py test_*.py *_tests.py *_test.py
DJANGO_SETTINGS_MODULE = pykeg.settings
Expand Down

0 comments on commit a438713

Please sign in to comment.