-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrun_tests.py
More file actions
29 lines (23 loc) · 779 Bytes
/
Copy pathrun_tests.py
File metadata and controls
29 lines (23 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import contextlib
import os
import shutil
import sys
import django
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.test.utils import get_runner
PROTECTED_MEDIA = "Deleting media directory outside of tests environment is forbidden."
def clean_media():
media = settings.IMPORTED_PATH
if "tests" not in media:
raise ImproperlyConfigured(PROTECTED_MEDIA)
with contextlib.suppress(FileNotFoundError):
shutil.rmtree(media)
if __name__ == "__main__":
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.test_settings"
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
failures = test_runner.run_tests(["tests"])
clean_media()
sys.exit(bool(failures))