From 176fe04e8d0fd00fb57b92c5f6838a6387917a71 Mon Sep 17 00:00:00 2001 From: Shane Lee Date: Wed, 27 Mar 2024 12:23:53 -0600 Subject: [PATCH] Make fixtures clean up even if the test fails --- tests/pytests/functional/modules/test_chocolatey.py | 8 +++++--- .../functional/states/chocolatey/test_bootstrap.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/pytests/functional/modules/test_chocolatey.py b/tests/pytests/functional/modules/test_chocolatey.py index d11cdf6cbed..904026dd93e 100644 --- a/tests/pytests/functional/modules/test_chocolatey.py +++ b/tests/pytests/functional/modules/test_chocolatey.py @@ -3,7 +3,7 @@ import pytest from salt.exceptions import CommandExecutionError pytestmark = [ - pytest.mark.destructive, + pytest.mark.destructive_test, pytest.mark.skip_unless_on_windows, pytest.mark.slow_test, pytest.mark.windows_whitelisted, @@ -23,8 +23,10 @@ def clean(chocolatey): except CommandExecutionError: chocolatey_version = None assert chocolatey_version is None - yield - chocolatey.unbootstrap() + try: + yield + finally: + chocolatey.unbootstrap() def test_bootstrap(chocolatey, clean): diff --git a/tests/pytests/functional/states/chocolatey/test_bootstrap.py b/tests/pytests/functional/states/chocolatey/test_bootstrap.py index 0d37d67c665..6b6bc62f558 100644 --- a/tests/pytests/functional/states/chocolatey/test_bootstrap.py +++ b/tests/pytests/functional/states/chocolatey/test_bootstrap.py @@ -28,8 +28,10 @@ def clean(chocolatey_mod): except CommandExecutionError: chocolatey_version = None assert chocolatey_version is None - yield - chocolatey_mod.unbootstrap() + try: + yield + finally: + chocolatey_mod.unbootstrap() @pytest.fixture() @@ -40,8 +42,10 @@ def installed(chocolatey_mod): except CommandExecutionError: chocolatey_version = None assert chocolatey_version is not None - yield - chocolatey_mod.unbootstrap() + try: + yield + finally: + chocolatey_mod.unbootstrap() def test_bootstrapped(chocolatey, chocolatey_mod, clean):