forked from openwisp/openwisp-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntests.py
More file actions
executable file
·56 lines (50 loc) · 1.6 KB
/
runtests.py
File metadata and controls
executable file
·56 lines (50 loc) · 1.6 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
import pytest
def run_tests(extra_args, settings_module, test_app):
"""
Run Django tests with the specified settings module in a separate subprocess.
"""
args = [
"./tests/manage.py",
"test",
test_app,
"--settings",
settings_module,
"--pythonpath",
"tests",
]
args.extend(extra_args)
if os.environ.get("COVERAGE_RUN", False):
# Since the Django tests are run in a separate process (using subprocess),
# we need to run coverage in the subprocess as well.
args = ["coverage", "run"] + args
result = subprocess.run(args)
if result.returncode != 0:
sys.exit(result.returncode)
if __name__ == "__main__":
# Configure Django settings for test execution
# (sets Celery to eager mode, configures in-memory channels layer, etc.)
os.environ.setdefault("TESTING", "1")
args = sys.argv.copy()[1:]
exclude_pytest = "--exclude-pytest" in args
if exclude_pytest:
args.pop(args.index("--exclude-pytest"))
# normal tests vs SAMPLE_APP
if not os.environ.get("SAMPLE_APP", False):
test_app = "openwisp_controller"
app_dir = "openwisp_controller/"
else:
test_app = "openwisp2"
app_dir = "tests/openwisp2/"
# Run Django tests
django_tests = run_tests(args, "openwisp2.settings", test_app)
# Run pytest tests
if not exclude_pytest:
# Used to test django-channels
sys.exit(pytest.main([app_dir]))
else:
sys.exit(django_tests)