Skip to content

Commit 39646d2

Browse files
committed
End session on session fixture failure
1 parent f7625ca commit 39646d2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/pytest_netdut/factories.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pytest
2020
from packaging import version
2121
from .wrappers import CLI, xapi
22+
import traceback
2223

2324
logger = logging.getLogger(__name__)
2425

@@ -296,9 +297,10 @@ def create_ssh_fixture(name):
296297
def _ssh(request):
297298
try:
298299
ssh = _CLI_wrapper(f"ssh://{request.getfixturevalue(f'{name}_hostname')}")
299-
except Exception as exc:
300+
except Exception:
300301
logging.error("Failed to create ssh fixture and log in")
301-
raise exc
302+
traceback.print_exc()
303+
pytest.exit("SSH fixture failure; terminating session")
302304
if ssh.cli_flavor == "mos":
303305
ssh.sendcmd("enable")
304306
yield ssh
@@ -314,9 +316,10 @@ def _console(request):
314316
# Ignore encoding errors for the console -- various conditions
315317
# cause non-UTF-8 characters to be received.
316318
console = _CLI_wrapper(console_url, ignore_encoding_errors=True)
317-
except Exception as exc:
319+
except Exception:
318320
logging.error("Failed to create console fixture and log in")
319-
raise exc
321+
traceback.print_exc()
322+
pytest.exit("Console fixture failure; terminating session")
320323
if console.cli_flavor == "mos":
321324
console.sendcmd("enable")
322325
yield console

0 commit comments

Comments
 (0)