From 99c3b84509c5fa8bed3263a962903f329124bd93 Mon Sep 17 00:00:00 2001 From: Kate Case Date: Tue, 29 Oct 2024 12:26:36 -0400 Subject: [PATCH] Update tests --- tests/unit/command/test_dependency.py | 16 ++++++++------ tests/unit/command/test_destroy.py | 30 ++++++++++++++------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/tests/unit/command/test_dependency.py b/tests/unit/command/test_dependency.py index f6f4b04fd..41333d73d 100644 --- a/tests/unit/command/test_dependency.py +++ b/tests/unit/command/test_dependency.py @@ -25,6 +25,10 @@ if TYPE_CHECKING: + from unittest.mock import Mock + + import pytest + from pytest_mock import MockerFixture from molecule import config @@ -33,15 +37,15 @@ # NOTE(retr0h): The use of the `patched_config_validate` fixture, disables # config.Config._validate from executing. Thus preventing odd side-effects # throughout patched.assert_called unit tests. -def test_dependency_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D103 +def test_dependency_execute( # noqa: D103 mocker: MockerFixture, # noqa: ARG001 - caplog, # noqa: ANN001 - patched_ansible_galaxy, # noqa: ANN001 - patched_config_validate, # noqa: ANN001, ARG001 + caplog: pytest.LogCaptureFixture, + patched_ansible_galaxy: Mock, + patched_config_validate: Mock, # noqa: ARG001 config_instance: config.Config, -): +) -> None: d = dependency.Dependency(config_instance) - d.execute() # type: ignore[no-untyped-call] + d.execute() patched_ansible_galaxy.assert_called_once_with() diff --git a/tests/unit/command/test_destroy.py b/tests/unit/command/test_destroy.py index daa1e832e..5fca7d778 100644 --- a/tests/unit/command/test_destroy.py +++ b/tests/unit/command/test_destroy.py @@ -27,18 +27,20 @@ if TYPE_CHECKING: + from unittest.mock import MagicMock, Mock + from pytest_mock import MockerFixture from molecule import config @pytest.fixture() -def _patched_ansible_destroy(mocker): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202 +def _patched_ansible_destroy(mocker: MockerFixture) -> MagicMock: return mocker.patch("molecule.provisioner.ansible.Ansible.destroy") @pytest.fixture() -def _patched_destroy_setup(mocker): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202 +def _patched_destroy_setup(mocker: MockerFixture) -> MagicMock: return mocker.patch("molecule.command.destroy.Destroy._setup") @@ -46,15 +48,15 @@ def _patched_destroy_setup(mocker): # type: ignore[no-untyped-def] # noqa: ANN # config.Config._validate from executing. Thus preventing odd side-effects # throughout patched.assert_called unit tests. @pytest.mark.skip(reason="destroy not running for delegated") -def test_destroy_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D103 +def test_destroy_execute( # noqa: D103 mocker: MockerFixture, # noqa: ARG001 - caplog, # noqa: ANN001 - patched_config_validate, # noqa: ANN001, ARG001 - _patched_ansible_destroy, # noqa: ANN001, PT019 + caplog: pytest.LogCaptureFixture, + patched_config_validate: Mock, # noqa: ARG001 + _patched_ansible_destroy: Mock, # noqa: PT019 config_instance: config.Config, -): +) -> None: d = destroy.Destroy(config_instance) - d.execute() # type: ignore[no-untyped-call] + d.execute() assert "destroy" in caplog.text @@ -71,16 +73,16 @@ def test_destroy_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D103 ["command_driver_delegated_section_data"], # noqa: PT007 indirect=True, ) -def test_execute_skips_when_destroy_strategy_is_never( # type: ignore[no-untyped-def] # noqa: ANN201, D103 - _patched_destroy_setup, # noqa: ANN001, PT019 - caplog, # noqa: ANN001 - _patched_ansible_destroy, # noqa: ANN001, PT019 +def test_execute_skips_when_destroy_strategy_is_never( # noqa: D103 + _patched_destroy_setup: Mock, # noqa: PT019 + caplog: pytest.LogCaptureFixture, + _patched_ansible_destroy: Mock, # noqa: PT019 config_instance: config.Config, -): +) -> None: config_instance.command_args = {"destroy": "never"} d = destroy.Destroy(config_instance) - d.execute() # type: ignore[no-untyped-call] + d.execute() msg = "Skipping, '--destroy=never' requested." assert msg in caplog.text