Skip to content

Commit 8818436

Browse files
committed
[tests] Fixed pytest suite
1 parent 2c4e5fc commit 8818436

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ addopts = -p no:warnings --create-db --reuse-db --nomigrations
33
DJANGO_SETTINGS_MODULE = openwisp2.settings
44
python_files = pytest*.py
55
python_classes = *Test*
6+
pythonpath = tests

runtests.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import subprocess
66
import sys
77

8-
import pytest
9-
108

119
def run_tests(args, settings_module):
1210
"""
@@ -20,6 +18,9 @@ def run_tests(args, settings_module):
2018

2119

2220
if __name__ == '__main__':
21+
# Configure Django settings for test execution
22+
# (sets Celery to eager mode, configures in-memory channels layer, etc.)
23+
os.environ.setdefault('TESTING', '1')
2324
base_args = sys.argv.copy()[1:]
2425
if not os.environ.get('SAMPLE_APP', False):
2526
test_app = 'openwisp_controller'
@@ -43,5 +44,8 @@ def run_tests(args, settings_module):
4344
run_tests(psql_args, 'openwisp2.postgresql_settings')
4445

4546
# Run pytest tests
46-
sys.path.insert(0, 'tests')
47-
sys.exit(pytest.main([app_dir]))
47+
result = subprocess.run(
48+
['pytest', app_dir],
49+
)
50+
if result.returncode != 0:
51+
sys.exit(result.returncode) # Exit immediately if tests fail

tests/openwisp2/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
55
DEBUG = True
6-
TESTING = sys.argv[1:2] == ['test']
6+
TESTING = os.environ.get('TESTING', False) or sys.argv[1:2] == ['test']
77
SELENIUM_HEADLESS = True if os.environ.get('SELENIUM_HEADLESS', False) else False
88
SHELL = 'shell' in sys.argv or 'shell_plus' in sys.argv
99
REDIS_URL = os.getenv('REDIS_URL', 'redis://localhost:6379')

0 commit comments

Comments
 (0)