Skip to content

Commit ffef8c1

Browse files
committed
[tests] Fixed tests for for deleting device
1 parent 8818436 commit ffef8c1

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

openwisp_controller/config/tests/test_selenium.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
24
from django.test import tag
35
from django.urls.base import reverse
@@ -246,8 +248,13 @@ def test_force_delete_device_with_deactivating_config(self):
246248
By.CSS_SELECTOR, '#deactivating-warning .messagelist .warning p'
247249
)
248250
self.find_element(by=By.CSS_SELECTOR, value='#warning-ack').click()
251+
# After accepting the warning, wee need to wait for the animation
252+
# to complete before trying to interact with the button,
253+
# otherwise the test may fail due to the button not being fully
254+
# visible or clickable yet.
255+
time.sleep(0.5)
249256
delete_confirm = self.find_element(
250-
By.CSS_SELECTOR, 'form[method="post"] input[type="submit"]'
257+
By.CSS_SELECTOR, 'form[method="post"] input[type="submit"]', timeout=10
251258
)
252259
delete_confirm.click()
253260
self.assertEqual(Device.objects.count(), 0)

runtests.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,30 @@
55
import subprocess
66
import sys
77

8+
import pytest
89

9-
def run_tests(args, settings_module):
10+
11+
def run_tests(extra_args, settings_module, test_app):
1012
"""
1113
Run Django tests with the specified settings module in a separate subprocess.
12-
Executes the command inside the 'tests/' directory.
1314
"""
14-
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
15-
result = subprocess.run(['python', 'manage.py'] + args, cwd='tests')
15+
args = [
16+
'./tests/manage.py',
17+
'test',
18+
test_app,
19+
'--settings',
20+
settings_module,
21+
'--pythonpath',
22+
'tests',
23+
]
24+
args.extend(extra_args)
25+
if os.environ.get('COVERAGE_RUN', False):
26+
# Since the Django tests are run in a separate process (using subprocess),
27+
# we need to run coverage in the subprocess as well.
28+
args = ['coverage', 'run'] + args
29+
result = subprocess.run(args)
1630
if result.returncode != 0:
17-
sys.exit(result.returncode) # Exit immediately if tests fail
31+
sys.exit(result.returncode)
1832

1933

2034
if __name__ == '__main__':
@@ -29,23 +43,17 @@ def run_tests(args, settings_module):
2943
test_app = 'openwisp2'
3044
app_dir = 'tests/openwisp2/'
3145
# 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')
46+
sqlite_args = ['--exclude-tag', 'selenium_tests'] + base_args
47+
run_tests(sqlite_args, 'openwisp2.settings', test_app)
3448

3549
# Run Selenium tests using PostgreSQL
3650
psql_args = [
37-
'test',
38-
test_app,
3951
'--tag',
4052
'db_tests',
4153
'--tag',
4254
'selenium_tests',
4355
] + base_args
44-
run_tests(psql_args, 'openwisp2.postgresql_settings')
56+
run_tests(psql_args, 'openwisp2.postgresql_settings', test_app)
4557

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

0 commit comments

Comments
 (0)