From 48c13326a37b9aed86c9670b39df70ad1a279c5e Mon Sep 17 00:00:00 2001 From: Pavel Novotny Date: Mon, 3 Jun 2024 17:43:36 +0200 Subject: [PATCH] session: execute browser teardown only once (#1413) 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 6b6423edb61b6e0b90aa180f2391b479c8791e2d) --- airgun/session.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airgun/session.py b/airgun/session.py index 897b729f2..d576e185f 100644 --- a/airgun/session.py +++ b/airgun/session.py @@ -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 @@ -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