Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions openwisp_utils/tests/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ def _setup_and_call(self, result, debug=False):
)
super()._setup_and_call(result, debug)
# IMPORTANT: a skip is not a success; propagate it as a skip and stop.
if getattr(result, "skipped", None):
for _, reason in result.skipped:
skip_reasons = []
if hasattr(result, "events"):
skip_reasons = [
event[2] for event in result.events if event[0] == "addSkip"
]
elif getattr(result, "skipped", None):
skip_reasons = [reason for _, reason in result.skipped]
if skip_reasons:
Comment thread
czarflix marked this conversation as resolved.
for reason in skip_reasons:
original_result.addSkip(self, reason)
if hasattr(original_result, "events") and hasattr(result, "events"):
Comment thread
czarflix marked this conversation as resolved.
Outdated
original_result.events = result.events
Expand Down
43 changes: 43 additions & 0 deletions tests/test_project/tests/test_selenium_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from unittest import TestResult, skip

from django.test import SimpleTestCase
from django.test.runner import RemoteTestResult
from openwisp_utils.tests.selenium import SeleniumTestMixin


class TestSeleniumMixinSkipHandling(SimpleTestCase):
def _run_skipped_test(self, result_class):
class SkippedSeleniumTest(SeleniumTestMixin, SimpleTestCase):
retry_max = 0
retry_delay = 0

@classmethod
def setUpClass(cls):
Comment thread
czarflix marked this conversation as resolved.
Outdated
pass

@classmethod
def tearDownClass(cls):
pass

@skip("skip propagation regression test")
def test_skip(self):
pass

test = SkippedSeleniumTest("test_skip")
if result_class is RemoteTestResult:
result = result_class(stream=None, descriptions=None, verbosity=0)
else:
result = result_class()
test._setup_and_call(result)
return result

def test_setup_and_call_propagates_skip_to_standard_result(self):
result = self._run_skipped_test(TestResult)

self.assertEqual(len(result.skipped), 1)
self.assertEqual(result.skipped[0][1], "skip propagation regression test")

def test_setup_and_call_records_skip_event_for_remote_result(self):
result = self._run_skipped_test(RemoteTestResult)

self.assertIn(("addSkip", 0, "skip propagation regression test"), result.events)
Loading