Skip to content

Commit d5085f4

Browse files
committed
Better exception handling.
1 parent 65213d5 commit d5085f4

File tree

10 files changed

+32
-32
lines changed

10 files changed

+32
-32
lines changed

examples/gui_test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
try:
77
# Python 2
88
from Tkinter import Tk, Frame, Button, Label
9-
except:
9+
except Exception:
1010
# Python 3
1111
from tkinter import Tk, Frame, Button, Label
1212
import os

seleniumbase/common/encryption.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def str_xor(string, key):
1919
try:
2020
result = "".join(
2121
[chr(ord(c1) ^ ord(c2)) for (c1, c2) in zip(string, key)])
22-
except:
22+
except Exception:
2323
string = string.decode('utf-8')
2424
result = "".join(
2525
[chr(ord(c1) ^ ord(c2)) for (c1, c2) in zip(string, key)])
@@ -80,7 +80,7 @@ def ord_string_sum(string):
8080
try:
8181
for c in string:
8282
count += ord(c)
83-
except:
83+
except Exception:
8484
string = string.decode('utf-8')
8585
for c in string:
8686
count += ord(c)

seleniumbase/common/obfuscate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def main():
2626
time.sleep(0.07)
2727
print(encryption.decrypt(password))
2828
time.sleep(0.21)
29-
except:
29+
except KeyboardInterrupt:
3030
print("\nExiting...\n")
3131

3232

seleniumbase/common/unobfuscate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main():
1616
try:
1717
# Python 2 has the raw_input() method. Python 3 does not.
1818
input_method = raw_input # noqa: ignore=F821
19-
except:
19+
except Exception:
2020
input_method = input # Using Python 3
2121
try:
2222
while(1):
@@ -26,7 +26,7 @@ def main():
2626
time.sleep(0.07)
2727
print(encryption.decrypt(code))
2828
time.sleep(0.21)
29-
except:
29+
except KeyboardInterrupt:
3030
print("\nExiting...\n")
3131

3232

seleniumbase/core/browser_launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def get_local_driver(browser_name, headless):
147147
firefox_driver = webdriver.Firefox(
148148
firefox_profile=profile, capabilities=firefox_capabilities)
149149
return firefox_driver
150-
except:
150+
except Exception:
151151
return webdriver.Firefox()
152152
if browser_name == constants.Browser.INTERNET_EXPLORER:
153153
return webdriver.Ie()

seleniumbase/core/log_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def log_test_failure_data(test, test_logpath, driver, browser):
2626
traceback_list = traceback.format_list(
2727
traceback.extract_tb(traceback_address)[1:])
2828
traceback_message = ''.join(traceback_list).strip()
29-
except:
29+
except Exception:
3030
exc_message = "(Unknown Exception)"
3131
traceback_message = "(Unknown Traceback)"
3232
data_to_save.append("Traceback: " + traceback_message)

seleniumbase/core/s3_manager.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class S3LoggingBucket(object):
1212
"""
13-
A class to upload our log files from tests to S3, from
14-
whence we can share them.
13+
A class to upload log files from tests to S3.
14+
Those files can then be shared easily.
1515
"""
1616

1717
def __init__(self,
@@ -26,16 +26,16 @@ def __init__(self,
2626
self.bucket_url = bucket_url
2727

2828
def get_key(self, _name):
29-
"""create a new Key instance with the given name"""
29+
""" Create a new Key instance with the given name. """
3030
return Key(bucket=self.bucket, name=_name)
3131

3232
def get_bucket(self):
33-
"""return the bucket we're using"""
33+
""" Return the bucket being used. """
3434
return self.bucket
3535

3636
def upload_file(self, file_name, file_path):
37-
"""upload a given file from the file_path to the bucket
38-
with the new name/path file_name"""
37+
""" Upload a given file from the file_path to the bucket
38+
with the new name/path file_name. """
3939
upload_key = Key(bucket=self.bucket, name=file_name)
4040
content_type = "text/plain"
4141
if file_name.endswith(".html"):
@@ -51,13 +51,13 @@ def upload_file(self, file_name, file_path):
5151
upload_key.generate_url(expires_in=3600).split("?")[0]
5252
try:
5353
upload_key.make_public()
54-
except:
54+
except Exception:
5555
pass
5656
return file_name
5757

5858
def upload_index_file(self, test_address, timestamp):
59-
"""create an index.html file with links to all the log files we
60-
just uploaded"""
59+
""" Create an index.html file with links to all the log files we
60+
just uploaded. """
6161
global already_uploaded_files
6262
already_uploaded_files = list(set(already_uploaded_files))
6363
already_uploaded_files.sort()
@@ -74,8 +74,8 @@ def upload_index_file(self, test_address, timestamp):
7474
return "%s%s" % (self.bucket_url, file_name)
7575

7676
def save_uploaded_file_names(self, files):
77-
"""We keep record of file names that have been uploaded. We upload log
78-
files related to each test after its execution. Once we're done, we
79-
use already_uploaded_files to create an index file"""
77+
""" Keep a record of all file names that've been uploaded. Upload log
78+
files related to each test after its execution. Once done, use
79+
already_uploaded_files to create an index file. """
8080
global already_uploaded_files
8181
already_uploaded_files.extend(files)

seleniumbase/fixtures/base_case.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ def _get_new_timeout(self, timeout):
11701170
timeout_multiplier = 0.5
11711171
timeout = int(math.ceil(timeout_multiplier * timeout))
11721172
return timeout
1173-
except:
1173+
except Exception:
11741174
# Wrong data type for timeout_multiplier (expecting int or float)
11751175
return timeout
11761176

@@ -1185,7 +1185,7 @@ def _get_exception_message(self):
11851185
if exception_info:
11861186
try:
11871187
exc_message = exception_info[0][1][1]
1188-
except:
1188+
except Exception:
11891189
exc_message = "(Unknown Exception)"
11901190
else:
11911191
exc_message = "(Unknown Exception)"
@@ -1474,7 +1474,7 @@ def _add_pytest_html_extra(self):
14741474
name='Screenshot')
14751475
self._html_report_extra.append(extra_url)
14761476
self._html_report_extra.append(extra_image)
1477-
except:
1477+
except Exception:
14781478
pass
14791479

14801480
def tearDown(self):
@@ -1541,8 +1541,8 @@ def tearDown(self):
15411541
self.driver.quit()
15421542
except AttributeError:
15431543
pass
1544-
except:
1545-
print("No driver to quit.")
1544+
except Exception:
1545+
pass
15461546
self.driver = None
15471547
if self.headless:
15481548
if self.headless_active:
@@ -1587,6 +1587,6 @@ def tearDown(self):
15871587
self.driver.quit()
15881588
except AttributeError:
15891589
pass
1590-
except:
1591-
print("No driver to quit.")
1590+
except Exception:
1591+
pass
15921592
self.driver = None

seleniumbase/plugins/pytest_plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ def pytest_runtest_teardown(item):
159159
try:
160160
if hasattr(self, 'driver') and self.driver:
161161
self.driver.quit()
162-
except:
162+
except Exception:
163163
pass
164164
try:
165165
if hasattr(self, 'headless') and self.headless:
166166
if self.headless_active:
167167
if hasattr(self, 'display') and self.display:
168168
self.display.stop()
169-
except:
169+
except Exception:
170170
pass
171-
except:
171+
except Exception:
172172
pass
173173

174174

@@ -182,5 +182,5 @@ def pytest_runtest_makereport(item, call):
182182
extra_report = item._testcase._html_report_extra
183183
extra = getattr(report, 'extra', [])
184184
report.extra = extra + extra_report
185-
except:
185+
except Exception:
186186
pass

seleniumbase/plugins/selenium_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def afterTest(self, test):
125125
self.driver.quit()
126126
except AttributeError:
127127
pass
128-
except:
128+
except Exception:
129129
pass
130130
if self.options.headless:
131131
if self.headless_active:

0 commit comments

Comments
 (0)