def tearDown(self):
has_exception = False<EOL>if sys.version.startswith('<STR_LIT:3>') and hasattr(self, '<STR_LIT>'):<EOL><INDENT>if hasattr(self._outcome, '<STR_LIT>') and self._outcome.errors:<EOL><INDENT>has_exception = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>has_exception = sys.exc_info()[<NUM_LIT:1>] is not None<EOL><DEDENT>if self.__delayed_assert_failures:<EOL><INDENT>print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>if not has_exception:<EOL><INDENT>self.process_delayed_asserts()<EOL><DEDENT>else:<EOL><INDENT>self.process_delayed_asserts(print_only=True)<EOL><DEDENT><DEDENT>self.is_pytest = None<EOL>try:<EOL><INDENT>self.is_pytest = sb_config.is_pytest<EOL><DEDENT>except Exception:<EOL><INDENT>self.is_pytest = False<EOL><DEDENT>if self.is_pytest:<EOL><INDENT>test_id = "<STR_LIT>" % (self.__class__.__module__,<EOL>self.__class__.__name__,<EOL>self._testMethodName)<EOL>try:<EOL><INDENT>with_selenium = self.with_selenium<EOL><DEDENT>except Exception:<EOL><INDENT>sub_class_name = str(<EOL>self.__class__.__bases__[<NUM_LIT:0>]).split('<STR_LIT:.>')[-<NUM_LIT:1>].split("<STR_LIT:'>")[<NUM_LIT:0>]<EOL>sub_file_name = str(self.__class__.__bases__[<NUM_LIT:0>]).split('<STR_LIT:.>')[-<NUM_LIT:2>]<EOL>sub_file_name = sub_file_name + "<STR_LIT>"<EOL>class_name = str(self.__class__).split('<STR_LIT:.>')[-<NUM_LIT:1>].split("<STR_LIT:'>")[<NUM_LIT:0>]<EOL>file_name = str(self.__class__).split('<STR_LIT:.>')[-<NUM_LIT:2>] + "<STR_LIT>"<EOL>class_name_used = sub_class_name<EOL>file_name_used = sub_file_name<EOL>if sub_class_name == "<STR_LIT>":<EOL><INDENT>class_name_used = class_name<EOL>file_name_used = file_name<EOL><DEDENT>fix_setup = "<STR_LIT>" % class_name_used<EOL>fix_teardown = "<STR_LIT>" % class_name_used<EOL>message = ("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (class_name_used, file_name_used,<EOL>fix_setup, fix_teardown))<EOL>raise Exception(message)<EOL><DEDENT>if with_selenium:<EOL><INDENT>if has_exception:<EOL><INDENT>self.__add_pytest_html_extra()<EOL><DEDENT>if self.with_testing_base and not has_exception and (<EOL>self.save_screenshot_after_test):<EOL><INDENT>test_logpath = self.log_path + "<STR_LIT:/>" + test_id<EOL>if not os.path.exists(test_logpath):<EOL><INDENT>try:<EOL><INDENT>os.makedirs(test_logpath)<EOL><DEDENT>except Exception:<EOL><INDENT>pass  <EOL><DEDENT><DEDENT>if not self.__last_page_screenshot_png:<EOL><INDENT>self.__set_last_page_screenshot()<EOL><DEDENT>log_helper.log_screenshot(<EOL>test_logpath,<EOL>self.driver,<EOL>self.__last_page_screenshot_png)<EOL>self.__add_pytest_html_extra()<EOL><DEDENT>if self.with_testing_base and has_exception:<EOL><INDENT>test_logpath = self.log_path + "<STR_LIT:/>" + test_id<EOL>if not os.path.exists(test_logpath):<EOL><INDENT>try:<EOL><INDENT>os.makedirs(test_logpath)<EOL><DEDENT>except Exception:<EOL><INDENT>pass  <EOL><DEDENT><DEDENT>if ((not self.with_screen_shots) and (<EOL>not self.with_basic_test_info) and (<EOL>not self.with_page_source)):<EOL><INDENT>if not self.__last_page_screenshot_png:<EOL><INDENT>self.__set_last_page_screenshot()<EOL><DEDENT>log_helper.log_screenshot(<EOL>test_logpath,<EOL>self.driver,<EOL>self.__last_page_screenshot_png)<EOL>log_helper.log_test_failure_data(<EOL>self, test_logpath, self.driver, self.browser)<EOL>log_helper.log_page_source(test_logpath, self.driver)<EOL><DEDENT>else:<EOL><INDENT>if self.with_screen_shots:<EOL><INDENT>if not self.__last_page_screenshot_png:<EOL><INDENT>self.__set_last_page_screenshot()<EOL><DEDENT>log_helper.log_screenshot(<EOL>test_logpath,<EOL>self.driver,<EOL>self.__last_page_screenshot_png)<EOL><DEDENT>if self.with_basic_test_info:<EOL><INDENT>log_helper.log_test_failure_data(<EOL>self, test_logpath, self.driver, self.browser)<EOL><DEDENT>if self.with_page_source:<EOL><INDENT>log_helper.log_page_source(<EOL>test_logpath, self.driver)<EOL><DEDENT><DEDENT><DEDENT>self.__quit_all_drivers()<EOL><DEDENT>if self.headless:<EOL><INDENT>if self.headless_active:<EOL><INDENT>self.display.stop()<EOL>self.display = None<EOL><DEDENT><DEDENT>if self.with_db_reporting:<EOL><INDENT>if has_exception:<EOL><INDENT>self.__insert_test_result(constants.State.ERROR, True)<EOL><DEDENT>else:<EOL><INDENT>self.__insert_test_result(constants.State.PASS, False)<EOL><DEDENT>runtime = int(time.time() * <NUM_LIT:1000>) - self.execution_start_time<EOL>self.testcase_manager.update_execution_data(<EOL>self.execution_guid, runtime)<EOL><DEDENT>if self.with_s3_logging and has_exception:<EOL><INDENT>"""<STR_LIT>"""<EOL>from seleniumbase.core.s3_manager import S3LoggingBucket<EOL>s3_bucket = S3LoggingBucket()<EOL>guid = str(uuid.uuid4().hex)<EOL>path = "<STR_LIT>" % (self.log_path, test_id)<EOL>uploaded_files = []<EOL>for logfile in os.listdir(path):<EOL><INDENT>logfile_name = "<STR_LIT>" % (guid,<EOL>test_id,<EOL>logfile.split(path)[-<NUM_LIT:1>])<EOL>s3_bucket.upload_file(logfile_name,<EOL>"<STR_LIT>" % (path, logfile))<EOL>uploaded_files.append(logfile_name)<EOL><DEDENT>s3_bucket.save_uploaded_file_names(uploaded_files)<EOL>index_file = s3_bucket.upload_index_file(test_id, guid)<EOL>print("<STR_LIT>" % index_file)<EOL>logging.error(<EOL>"<STR_LIT>" % index_file)<EOL>if self.with_db_reporting:<EOL><INDENT>self.testcase_manager = TestcaseManager(self.database_env)<EOL>data_payload = TestcaseDataPayload()<EOL>data_payload.guid = self.testcase_guid<EOL>data_payload.logURL = index_file<EOL>self.testcase_manager.update_testcase_log_url(data_payload)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if has_exception:<EOL><INDENT>test_id = "<STR_LIT>" % (self.__class__.__module__,<EOL>self.__class__.__name__,<EOL>self._testMethodName)<EOL>test_logpath = "<STR_LIT>" + test_id<EOL>if not os.path.exists(test_logpath):<EOL><INDENT>try:<EOL><INDENT>os.makedirs(test_logpath)<EOL><DEDENT>except Exception:<EOL><INDENT>pass  <EOL><DEDENT><DEDENT>log_helper.log_test_failure_data(<EOL>self, test_logpath, self.driver, self.browser)<EOL>if len(self._drivers_list) > <NUM_LIT:0>:<EOL><INDENT>if not self.__last_page_screenshot_png:<EOL><INDENT>self.__set_last_page_screenshot()<EOL><DEDENT>log_helper.log_screenshot(<EOL>test_logpath,<EOL>self.driver,<EOL>self.__last_page_screenshot_png)<EOL>log_helper.log_page_source(test_logpath, self.driver)<EOL><DEDENT><DEDENT>elif self.save_screenshot_after_test:<EOL><INDENT>test_id = "<STR_LIT>" % (self.__class__.__module__,<EOL>self.__class__.__name__,<EOL>self._testMethodName)<EOL>test_logpath = "<STR_LIT>" + test_id<EOL>if not os.path.exists(test_logpath):<EOL><INDENT>try:<EOL><INDENT>os.makedirs(test_logpath)<EOL><DEDENT>except Exception:<EOL><INDENT>pass  <EOL><DEDENT><DEDENT>if not self.__last_page_screenshot_png:<EOL><INDENT>self.__set_last_page_screenshot()<EOL><DEDENT>log_helper.log_screenshot(<EOL>test_logpath,<EOL>self.driver,<EOL>self.__last_page_screenshot_png)<EOL><DEDENT>if self.report_on:<EOL><INDENT>self._last_page_screenshot = self.__last_page_screenshot_png<EOL>try:<EOL><INDENT>self._last_page_url = self.get_current_url()<EOL><DEDENT>except Exception:<EOL><INDENT>self._last_page_url = "<STR_LIT>"<EOL><DEDENT><DEDENT>self.__quit_all_drivers()<EOL><DEDENT>
Be careful if a subclass of BaseCase overrides setUp()
You'll need to add the following line to the subclass's tearDown():
super(SubClassOfBaseCase, self).tearDown()