@@ -307,6 +307,7 @@ def open(self, url):
307
307
pass # Odd issue where the open did happen. Continue.
308
308
else:
309
309
raise
310
+ unittest.has_exception = False
310
311
if (
311
312
self.undetectable
312
313
or (
@@ -4119,6 +4120,7 @@ def wait_for_ready_state_complete(self, timeout=None):
4119
4120
and settings.SKIP_JS_WAITS
4120
4121
):
4121
4122
time.sleep(0.05)
4123
+ unittest.has_exception = False
4122
4124
return True
4123
4125
4124
4126
def wait_for_angularjs(self, timeout=None, **kwargs):
@@ -6360,12 +6362,14 @@ def assert_pdf_text(
6360
6362
)
6361
6363
if type(page) is int:
6362
6364
if text not in pdf_text:
6365
+ unittest.has_exception = True
6363
6366
raise Exception(
6364
6367
"PDF [%s] is missing expected text [%s] on "
6365
6368
"page [%s]!" % (pdf, text, page)
6366
6369
)
6367
6370
else:
6368
6371
if text not in pdf_text:
6372
+ unittest.has_exception = True
6369
6373
raise Exception(
6370
6374
"PDF [%s] is missing expected text [%s]!" % (pdf, text)
6371
6375
)
@@ -6740,40 +6744,52 @@ def assert_downloaded_file(self, file, timeout=None, browser=False):
6740
6744
def assert_true(self, expr, msg=None):
6741
6745
"""Asserts that the expression is True.
6742
6746
Will raise an exception if the statement if False."""
6747
+ unittest.has_exception = True
6743
6748
self.assertTrue(expr, msg=msg)
6749
+ unittest.has_exception = False
6744
6750
6745
6751
def assert_false(self, expr, msg=None):
6746
6752
"""Asserts that the expression is False.
6747
6753
Will raise an exception if the statement if True."""
6754
+ unittest.has_exception = True
6748
6755
self.assertFalse(expr, msg=msg)
6756
+ unittest.has_exception = False
6749
6757
6750
6758
def assert_equal(self, first, second, msg=None):
6751
6759
"""Asserts that the two values are equal.
6752
6760
Will raise an exception if the values are not equal."""
6761
+ unittest.has_exception = True
6753
6762
self.assertEqual(first, second, msg=msg)
6763
+ unittest.has_exception = False
6754
6764
6755
6765
def assert_not_equal(self, first, second, msg=None):
6756
6766
"""Asserts that the two values are not equal.
6757
6767
Will raise an exception if the values are equal."""
6768
+ unittest.has_exception = True
6758
6769
self.assertNotEqual(first, second, msg=msg)
6770
+ unittest.has_exception = False
6759
6771
6760
6772
def assert_in(self, first, second, msg=None):
6761
6773
"""Asserts that the first string is in the second string.
6762
6774
Will raise an exception if the first string is not in the second."""
6775
+ unittest.has_exception = True
6763
6776
self.assertIn(first, second, msg=msg)
6777
+ unittest.has_exception = False
6764
6778
6765
6779
def assert_not_in(self, first, second, msg=None):
6766
6780
"""Asserts that the first string is not in the second string.
6767
6781
Will raise an exception if the first string is in the second string."""
6782
+ unittest.has_exception = True
6768
6783
self.assertNotIn(first, second, msg=msg)
6784
+ unittest.has_exception = False
6769
6785
6770
6786
def assert_raises(self, *args, **kwargs):
6771
6787
"""Asserts that the following block of code raises an exception.
6772
6788
Will raise an exception if the block of code has no exception.
6773
6789
Usage Example =>
6774
- # Verify that the expected exception is raised.
6775
- with self.assert_raises(Exception):
6776
- raise Exception("Expected Exception!") """
6790
+ # Verify that the expected exception is raised.
6791
+ with self.assert_raises(Exception):
6792
+ raise Exception("Expected Exception!") """
6777
6793
return self.assertRaises(*args, **kwargs)
6778
6794
6779
6795
def wait_for_attribute(
@@ -6884,9 +6900,11 @@ def assert_title(self, title):
6884
6900
self.wait_for_ready_state_complete()
6885
6901
time.sleep(2)
6886
6902
actual = self.get_page_title().strip()
6903
+ unittest.has_exception = True
6887
6904
self.assertEqual(
6888
6905
expected, actual, error % (expected, actual)
6889
6906
)
6907
+ unittest.has_exception = False
6890
6908
if self.demo_mode and not self.recorder_mode:
6891
6909
a_t = "ASSERT TITLE"
6892
6910
if self._language != "English":
@@ -6931,9 +6949,11 @@ def assert_title_contains(self, substring):
6931
6949
self.wait_for_ready_state_complete()
6932
6950
time.sleep(2)
6933
6951
actual = self.get_page_title().strip()
6952
+ unittest.has_exception = True
6934
6953
self.assertIn(
6935
6954
expected, actual, error % (expected, actual)
6936
6955
)
6956
+ unittest.has_exception = False
6937
6957
if self.demo_mode and not self.recorder_mode:
6938
6958
a_t = "ASSERT TITLE CONTAINS"
6939
6959
if self._language != "English":
@@ -6968,7 +6988,9 @@ def assert_url(self, url):
6968
6988
self.wait_for_ready_state_complete()
6969
6989
time.sleep(2)
6970
6990
actual = self.get_current_url().strip()
6991
+ unittest.has_exception = True
6971
6992
self.assertEqual(expected, actual, error % (expected, actual))
6993
+ unittest.has_exception = False
6972
6994
if self.demo_mode and not self.recorder_mode:
6973
6995
a_u = "ASSERT URL"
6974
6996
if self._language != "English":
@@ -7006,7 +7028,9 @@ def assert_url_contains(self, substring):
7006
7028
self.wait_for_ready_state_complete()
7007
7029
time.sleep(2)
7008
7030
actual = self.get_current_url().strip()
7031
+ unittest.has_exception = True
7009
7032
self.assertIn(expected, actual, error % (expected, actual))
7033
+ unittest.has_exception = False
7010
7034
if self.demo_mode and not self.recorder_mode:
7011
7035
a_u = "ASSERT URL CONTAINS"
7012
7036
if self._language != "English":
@@ -7103,6 +7127,7 @@ def assert_no_js_errors(self, exclude=[]):
7103
7127
er_str = str(errors)
7104
7128
er_str = er_str.replace("[{", "[\n{").replace("}, {", "},\n{")
7105
7129
current_url = self.get_current_url()
7130
+ unittest.has_exception = True
7106
7131
raise Exception(
7107
7132
"JavaScript errors found on %s => %s" % (current_url, er_str)
7108
7133
)
@@ -9812,6 +9837,7 @@ def __get_new_timeout(self, timeout):
9812
9837
9813
9838
def __check_scope(self):
9814
9839
if hasattr(self, "browser"): # self.browser stores the type of browser
9840
+ unittest.has_exception = False
9815
9841
return # All good: setUp() already initialized variables in "self"
9816
9842
else:
9817
9843
message = (
@@ -9827,6 +9853,7 @@ def __check_scope(self):
9827
9853
"\n variables, which are initialized during the setUp() method"
9828
9854
"\n that runs automatically before all tests called by pytest."
9829
9855
)
9856
+ unittest.has_exception = True
9830
9857
raise OutOfScopeException(message)
9831
9858
9832
9859
############
@@ -10082,6 +10109,7 @@ def process_deferred_asserts(self, print_only=False):
10082
10109
if print_only:
10083
10110
print(exception_output)
10084
10111
else:
10112
+ unittest.has_exception = True
10085
10113
raise Exception(exception_output.replace("\\n", "\n"))
10086
10114
10087
10115
############
@@ -13874,6 +13902,8 @@ def setUp(self, masterqa_mode=False):
13874
13902
# Some actions such as hover-clicking are different on mobile.
13875
13903
self.mobile_emulator = False
13876
13904
13905
+ unittest.has_exception = False
13906
+
13877
13907
# Configure the test time limit (if used).
13878
13908
self.set_time_limit(self.time_limit)
13879
13909
@@ -14158,6 +14188,8 @@ def __has_exception(self):
14158
14188
has_exception = sys.exc_info()[1] is not None
14159
14189
if self.__will_be_skipped and hasattr(self, "_using_sb_fixture"):
14160
14190
has_exception = False
14191
+ if python3_11_or_newer and unittest.has_exception:
14192
+ has_exception = True
14161
14193
return has_exception
14162
14194
14163
14195
def __get_test_id(self):
0 commit comments