Skip to content

Commit

Permalink
test: clean up functional test patchers after webdriverexception
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Jan 24, 2019
1 parent ba02875 commit e92a04a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions securedrop/tests/functional/functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import errno
import mock
import os
import pytest
import signal
import socket
import time
Expand Down Expand Up @@ -146,7 +147,14 @@ def start_journalist_server(app):
break

if not hasattr(self, 'override_driver'):
self.driver = self._create_webdriver(self._prepare_webdriver())
try:
self.driver = self._create_webdriver(self._prepare_webdriver())
except WebDriverException as e:
# Exceptions during driver setup will result in the teardown not being called.
# Let's teardown and _then_ fail the test so that the patchers are cleaned
# up for the subsequent tests.
self.teardown()
pytest.fail(e)

# Polls the DOM to wait for elements. To read more about why
# this is necessary:
Expand Down Expand Up @@ -182,7 +190,7 @@ def key_available(filesystem_id):
def teardown(self):
self.patcher.stop()
env.teardown()
if not hasattr(self, 'override_driver'):
if hasattr(self, 'driver') and not hasattr(self, 'override_driver'):
self.driver.quit()
self.source_process.terminate()
self.journalist_process.terminate()
Expand Down
6 changes: 5 additions & 1 deletion securedrop/tests/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def teardown():
if t.is_alive() and not isinstance(t, threading._MainThread):
t.join()
db.session.remove()
shutil.rmtree(config.TEMP_DIR)
try:
shutil.rmtree(config.TEMP_DIR)
except OSError:
# Then check the directory was already deleted
assert not os.path.exists(config.TEMP_DIR)
try:
shutil.rmtree(config.SECUREDROP_DATA_ROOT)
# safeguard for #844
Expand Down

0 comments on commit e92a04a

Please sign in to comment.