Make fixtures clean up even if the test fails

This commit is contained in:
Shane Lee 2024-03-27 12:23:53 -06:00 committed by Pedro Algarvio
parent eb785bdf30
commit 176fe04e8d
2 changed files with 13 additions and 7 deletions

View file

@ -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):

View file

@ -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):