From 44eac57595279335a9493c846cad264aa7e183f4 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Fri, 9 Dec 2022 15:09:44 +0100 Subject: [PATCH] behave: Properly support @destructive tests --- behave/features/environment.py | 5 +++-- behave/features/steps/podman.py | 15 ++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/behave/features/environment.py b/behave/features/environment.py index f14e9d34..93fa77df 100644 --- a/behave/features/environment.py +++ b/behave/features/environment.py @@ -20,8 +20,9 @@ def before_scenario(context, scenario): def after_scenario(context, scenario): if "destructive" in scenario.tags: # start a new container after a destructive test - context.podman.kill() - context.podman = podman.Podman(context) + # we must use an existing podman instance defined in `before_all` due to context attribute life-cycle: + # https://behave.readthedocs.io/en/stable/context_attributes.html + context.podman.restart() context.osc.clear() common.check_exit_code(context) diff --git a/behave/features/steps/podman.py b/behave/features/steps/podman.py index 75d12e10..ae9bc5ff 100644 --- a/behave/features/steps/podman.py +++ b/behave/features/steps/podman.py @@ -8,9 +8,7 @@ class Podman: self.context = context debug(context, "Podman.__init__()") self.container_id = None - self.run() - self.wait_on_systemd() - self.port = self.get_port() + self.start() def __del__(self): try: @@ -33,8 +31,8 @@ class Podman: debug(self.context, "> stderr:", proc.stderr) return proc - def run(self): - debug(self.context, "Podman.run()") + def start(self): + debug(self.context, "Podman.start()") args = [ "run", "--name", "obs-server-behave", @@ -50,6 +48,8 @@ class Podman: proc = self._run(args) lines = proc.stdout.strip().splitlines() self.container_id = lines[-1] + self.wait_on_systemd() + self.port = self.get_port() def kill(self): if not self.container_id: @@ -59,6 +59,11 @@ class Podman: self._run(args) self.container_id = None + def restart(self): + debug(self.context, "Podman.restart()") + self.kill() + self.start() + def wait_on_systemd(self): args = [ "exec",