From a2c5534afac03e9a79640e5ef7c50bee3827282a Mon Sep 17 00:00:00 2001 From: Satellite QE <115476073+Satellite-QE@users.noreply.github.com> Date: Wed, 29 May 2024 08:16:55 -0400 Subject: [PATCH] [6.12.z] ui_session: return airgun session as a context manager (#15156) ui_session: return airgun session as a context manager (#15050) In `Satellite.ui_session()` context manager method, `airgun.session.Session()` is also a context manager and needs to be returned using the `with-yield` contruct, so the Session's `__enter__` and `__exit__` methods are executed. This fixes the problem where `Session.__exit__()` method was not called and thus screenshot was not taken and the browser window was not closed at the end of the test. Also the `except Exception: raise` part was removed as redundant. (cherry picked from commit 2618e01768c22921302da9dc3841809bd74e840b) Co-authored-by: Pavel Novotny --- robottelo/hosts.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 8f52e34616a..7e4b1696275 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1766,17 +1766,15 @@ def get_caller(): return None try: - ui_session = Session( + with Session( session_name=testname or get_caller(), user=user or settings.server.admin_username, password=password or settings.server.admin_password, url=url, hostname=self.hostname, login=login, - ) - yield ui_session - except Exception: - raise + ) as ui_session: + yield ui_session finally: video_url = settings.ui.grid_url.replace( ':4444', f'/videos/{ui_session.ui_session_id}.mp4'