Skip to content

Commit d9cfc90

Browse files
authored
session: execute browser teardown only once (#1390)
The browser teardown in `airgun.session.Session.__exit__` should be executed only once. Because when `Session` is nested in multiple context managers(*), the `__exit__` method is called for each one and this causes that the second and further `webdriver.quit()` call will fail, because the browser session was already stopped. (*) for example in the robottelo `session` fixture in `robottelo/pytest_fixtures/core/ui.py`.
1 parent cf03f59 commit d9cfc90

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

airgun/session.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def __exit__(self, exc_type, exc_value, traceback):
232232
not risen not to shadow real session result.
233233
"""
234234
if self.browser is None:
235-
# browser was never started, don't do anything
235+
# browser hasn't been started or was already closed, don't do anything
236236
return
237237
LOGGER.info('Stopping UI session %r for user %r', self.name, self._user)
238238
passed = True if exc_type is None else False
@@ -242,7 +242,7 @@ def __exit__(self, exc_type, exc_value, traceback):
242242
except Exception as err: # - TODO: fix bare except
243243
LOGGER.exception(err)
244244
finally:
245-
self._factory.finalize(passed)
245+
self.browser = self._factory.finalize(passed)
246246

247247
def _open(self, entity):
248248
"""Initializes requested entity. If this is first time session

0 commit comments

Comments
 (0)