Skip to content

Commit fa4d7e9

Browse files
committed
[fix] Fixed runtests.py
1 parent 87497fd commit fa4d7e9

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

runtests.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,46 @@
22
# -*- coding: utf-8 -*-
33

44
import os
5+
import subprocess
56
import sys
67

78
import pytest
8-
from django.core.management import execute_from_command_line
99

1010

1111
def run_tests(args, settings_module):
1212
"""
13-
Run Django tests with the specified settings module.
13+
Run Django tests with the specified settings module in a separate subprocess.
14+
Executes the command inside the 'tests/' directory.
1415
"""
1516
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
16-
execute_from_command_line(args)
17+
result = subprocess.run(['python', 'manage.py'] + args, cwd='tests')
18+
if result.returncode != 0:
19+
sys.exit(result.returncode) # Exit immediately if tests fail
1720

1821

1922
if __name__ == '__main__':
20-
sys.path.insert(0, 'tests')
21-
22-
args = sys.argv
23-
args.insert(1, 'test')
23+
base_args = sys.argv.copy()[1:]
2424
if not os.environ.get('SAMPLE_APP', False):
25-
args.insert(2, 'openwisp_controller')
25+
test_app = 'openwisp_controller'
2626
app_dir = 'openwisp_controller/'
2727
else:
28-
args.insert(2, 'openwisp2')
28+
test_app = 'openwisp2'
2929
app_dir = 'tests/openwisp2/'
30-
3130
# Run all tests except Selenium tests using SQLite
32-
sqlite_args = args.copy()
33-
sqlite_args.extend(['--exclude-tag', 'selenium_tests'])
34-
run_tests(sqlite_args, settings_module='openwisp2.settings')
31+
sqlite_args = ['test', test_app, '--exclude-tag', 'selenium_tests'] + base_args
32+
run_tests(sqlite_args, 'openwisp2.settings')
3533

3634
# Run Selenium tests using PostgreSQL
37-
psql_args = args.copy()
38-
psql_args.extend(['--tag', 'selenium_tests', '--tag', 'db_tests'])
39-
run_tests(psql_args, settings_module='openwisp2.postgresql_settings')
40-
35+
psql_args = [
36+
'test',
37+
test_app,
38+
'--tag',
39+
'db_tests',
40+
'--tag',
41+
'selenium_tests',
42+
] + base_args
43+
run_tests(psql_args, 'openwisp2.postgresql_settings')
44+
45+
# Run pytest tests
46+
sys.path.insert(0, 'tests')
4147
sys.exit(pytest.main([app_dir]))

0 commit comments

Comments
 (0)