Created
May 14, 2013 01:00
-
-
Save klrmn/5572827 to your computer and use it in GitHub Desktop.
an __exit__ that does stuff before letting the error do it's thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScreenshotTaker(): | |
def __init__(self, webdriver, logger=None): | |
self.wd = webdriver | |
self.logger = logger | |
def __enter__(self): | |
pass | |
def __exit__(self, exec_type, value, tb): | |
"""i don't care what kind of exception it is, i want a screenshot.""" | |
timestamp = repr(time.time()).replace('.', '') | |
screenshot_filename = nose_selenium.SAVED_FILES_PATH + "/" + timestamp + ".png" | |
self.wd.get_screenshot_as_file(screenshot_filename) | |
if self.logger: | |
self.logger.error("ASSERT: Screenshot saved to %s" % screenshot_filename) | |
# return False # didn't work | |
# return True # didn't work | |
# raise value # didn't re-raise the original exception, got a different error instead | |
raise # same TypeErorr as above |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment