Skip to content

Commit

Permalink
Merge pull request #104 from seleniumbase/better-error-handling
Browse files Browse the repository at this point in the history
Better error handling for Pytest teardowns
  • Loading branch information
mdmintz authored May 18, 2017
2 parents 5f31a37 + 084742d commit 35791a9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
2 changes: 2 additions & 0 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,9 +1455,11 @@ def tearDown(self):
pass
except:
print("No driver to quit.")
self.driver = None
if self.headless:
if self.headless_active:
self.display.stop()
self.display = None
if self.with_db_reporting:
if sys.exc_info()[1] is not None:
self.__insert_test_result(constants.State.ERROR, True)
Expand Down
39 changes: 13 additions & 26 deletions seleniumbase/plugins/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import os
import pytest
import shutil
import sys
import time
from contextlib import contextmanager
from seleniumbase.config import settings
from seleniumbase.fixtures import constants

Expand Down Expand Up @@ -133,34 +131,23 @@ def pytest_runtest_setup():
def pytest_runtest_teardown(item):
""" This runs after every test with pytest """

# Make sure the web driver has exited properly
with suppress_stdout():
# Make sure webdriver has exited properly and any headless display
try:
self = item._testcase
try:
self = item._testcase
try:
if hasattr(self, 'driver') and self.driver:
self.driver.quit()
except:
pass
try:
if hasattr(self, 'headless') and self.headless:
if self.headless_active:
self.display.stop()
except:
pass
if hasattr(self, 'driver') and self.driver:
self.driver.quit()
except:
pass


@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
sys.stdout = devnull
try:
yield
finally:
sys.stdout = old_stdout
if hasattr(self, 'headless') and self.headless:
if self.headless_active:
if hasattr(self, 'display') and self.display:
self.display.stop()
except:
pass
except:
pass


@pytest.mark.hookwrapper
Expand Down
2 changes: 1 addition & 1 deletion server_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='seleniumbase',
version='1.3.22',
version='1.3.23',
description='Test Automation Framework - http://seleniumbase.com',
long_description='Automation Framework for Simple & Reliable Web Testing',
platforms='Mac * Windows * Linux * Docker',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='seleniumbase',
version='1.3.22',
version='1.3.23',
description='Test Automation Framework - http://seleniumbase.com',
long_description='Automation Framework for Simple & Reliable Web Testing',
platforms='Mac * Windows * Linux * Docker',
Expand Down

0 comments on commit 35791a9

Please sign in to comment.