66import sys
77
88
9- def run_tests (args , settings_module ):
9+ def run_tests (extra_args , settings_module , test_app ):
1010 """
1111 Run Django tests with the specified settings module in a separate subprocess.
1212 Executes the command inside the 'tests/' directory.
1313 """
14- os .environ ['DJANGO_SETTINGS_MODULE' ] = settings_module
15- result = subprocess .run (['python' , 'manage.py' ] + args , cwd = 'tests' )
14+ args = []
15+ if os .environ .get ('COVERAGE_RUN' , False ):
16+ args .extend (['coverage' , 'run' ])
17+ args .extend (
18+ [
19+ './tests/manage.py' ,
20+ 'test' ,
21+ test_app ,
22+ '--settings' ,
23+ settings_module ,
24+ '--pythonpath' ,
25+ 'tests' ,
26+ ]
27+ )
28+ args .extend (extra_args )
29+ result = subprocess .run (args )
1630 if result .returncode != 0 :
17- sys .exit (result .returncode ) # Exit immediately if tests fail
31+ # Exit immediately if tests fail
32+ sys .exit (result .returncode )
1833
1934
2035if __name__ == '__main__' :
@@ -29,19 +44,17 @@ def run_tests(args, settings_module):
2944 test_app = 'openwisp2'
3045 app_dir = 'tests/openwisp2/'
3146 # Run all tests except Selenium tests using SQLite
32- sqlite_args = ['test' , test_app , ' --exclude-tag' , 'selenium_tests' ] + base_args
33- run_tests (sqlite_args , 'openwisp2.settings' )
47+ sqlite_args = ['--exclude-tag' , 'selenium_tests' ] + base_args
48+ run_tests (sqlite_args , 'openwisp2.settings' , test_app )
3449
3550 # Run Selenium tests using PostgreSQL
3651 psql_args = [
37- 'test' ,
38- test_app ,
3952 '--tag' ,
4053 'db_tests' ,
4154 '--tag' ,
4255 'selenium_tests' ,
4356 ] + base_args
44- run_tests (psql_args , 'openwisp2.postgresql_settings' )
57+ run_tests (psql_args , 'openwisp2.postgresql_settings' , test_app )
4558
4659 # Run pytest tests
4760 result = subprocess .run (
0 commit comments