Skip to content

Commit

Permalink
session: execute browser teardown only once (#1413) (#1415)
Browse files Browse the repository at this point in the history
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`.

(cherry picked from commit 6b6423e)

Co-authored-by: Pavel Novotny <[email protected]>
  • Loading branch information
Satellite-QE and pnovotny authored Jun 3, 2024
1 parent 7619959 commit df39d37
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions airgun/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def __exit__(self, exc_type, exc_value, traceback):
not risen not to shadow real session result.
"""
if self.browser is None:
# browser was never started, don't do anything
# browser hasn't been started or was already closed, don't do anything
return
LOGGER.info('Stopping UI session %r for user %r', self.name, self._user)
passed = True if exc_type is None else False
Expand All @@ -240,7 +240,7 @@ def __exit__(self, exc_type, exc_value, traceback):
except Exception as err: # - TODO: fix bare except
LOGGER.exception(err)
finally:
self._factory.finalize(passed)
self.browser = self._factory.finalize(passed)

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

0 comments on commit df39d37

Please sign in to comment.