Due to context manager nature, __exit__() catches exceptions in CM body, but not in CM's __enter__() section. This means in case any exception happens in __enter__() (e.g. host is unreachable) - session won't be closed and browser will remain opened after test run.
The easiest way to solve this is probably to use try: except: in __enter__() method which will call __exit__() in case of exception.
Due to context manager nature,
__exit__()
catches exceptions in CM body, but not in CM's__enter__()
section. This means in case any exception happens in__enter__()
(e.g. host is unreachable) - session won't be closed and browser will remain opened after test run. The easiest way to solve this is probably to usetry: except:
in__enter__()
method which will call__exit__()
in case of exception.