Skip to content

Commit

Permalink
Make thread checks more robust
Browse files Browse the repository at this point in the history
- if a test has an exception, the ThreadWithResult variable (`test_case_thread_1` or `test_case_thread_2`) won't have a result attribute
  - performing `(getattr(test_case_thread_[1|2], 'failed', None) is None` effectively checks for exceptions
  • Loading branch information
shailshouryya committed Dec 28, 2020
1 parent 3b2de04 commit 27cc6a9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions python/tests/test_shared.py
Expand Up @@ -89,12 +89,12 @@ def run_tests_for(browsers_list):
while threading.active_count() - 1 != 0 and current < total:
# the threads are still running
time.sleep(7)
if 'thread_1_case' in locals(): test_case_thread_1.join()
if 'thread_2_case' in locals(): test_case_thread_2.join()
if 'test_case_thread_1' in locals(): test_case_thread_1.join()
if 'test_case_thread_2' in locals(): test_case_thread_2.join()
if 'thread_1_case' in locals(): log_test_info(f'{ISOFORMAT(NOW())}: Finished testing {[thread_1_case]}!', log_1_name)
if 'thread_2_case' in locals(): log_test_info(f'{ISOFORMAT(NOW())}: Finished testing {[thread_2_case]}!', log_2_name)
if 'thread_1_case' in locals() and test_case_thread_1.failed == 'Failed!': sys.exit()
if 'thread_2_case' in locals() and test_case_thread_2.failed == 'Failed!': sys.exit()
if 'test_case_thread_1' in locals() and (getattr(test_case_thread_1, 'failed', None) is None or test_case_thread_1.failed == 'Failed!'): sys.exit()
if 'test_case_thread_2' in locals() and (getattr(test_case_thread_2, 'failed', None) is None or test_case_thread_2.failed == 'Failed!'): sys.exit()
if 'thread_1_case' in locals() and 'thread_2_case' in locals(): log_test_info(f'{ISOFORMAT(NOW())}: Moving on to the next driver...\n' + '⏬ '*11, log_1_name, log_2_name)
elif 'thread_1_case' in locals(): log_test_info(f'{ISOFORMAT(NOW())}: Moving on to the next driver...\n' + '⏬ '*11, log_1_name)
elif 'thread_2_case' in locals(): log_test_info(f'{ISOFORMAT(NOW())}: Moving on to the next driver...\n' + '⏬ '*11, log_2_name)
Expand Down

0 comments on commit 27cc6a9

Please sign in to comment.