diff --git a/tests/unit/command/test_side_effect.py b/tests/unit/command/test_side_effect.py index 2b3a908aa..8724d7ecc 100644 --- a/tests/unit/command/test_side_effect.py +++ b/tests/unit/command/test_side_effect.py @@ -30,11 +30,18 @@ if TYPE_CHECKING: + from typing import Literal + from unittest.mock import MagicMock, Mock + from pytest_mock import MockerFixture + from molecule.types import ProvisionerData + @pytest.fixture() -def _command_provisioner_section_with_side_effect_data(): # type: ignore[no-untyped-def] # noqa: ANN202 +def _command_provisioner_section_with_side_effect_data() -> ( + dict[Literal["provisioner"], ProvisionerData] +): return { "provisioner": { "name": "ansible", @@ -44,7 +51,7 @@ def _command_provisioner_section_with_side_effect_data(): # type: ignore[no-unt @pytest.fixture() -def _patched_ansible_side_effect(mocker): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202 +def _patched_ansible_side_effect(mocker: MockerFixture) -> MagicMock: return mocker.patch("molecule.provisioner.ansible.Ansible.side_effect") @@ -56,18 +63,18 @@ def _patched_ansible_side_effect(mocker): # type: ignore[no-untyped-def] # noq ["_command_provisioner_section_with_side_effect_data"], # noqa: PT007 indirect=True, ) -def test_side_effect_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D103 +def test_side_effect_execute( # noqa: D103 mocker: MockerFixture, # noqa: ARG001 - _patched_ansible_side_effect, # noqa: ANN001, PT019 - caplog, # noqa: ANN001 - patched_config_validate, # noqa: ANN001, ARG001 + _patched_ansible_side_effect: Mock, # noqa: PT019 + caplog: pytest.LogCaptureFixture, + patched_config_validate: Mock, # noqa: ARG001 config_instance: config.Config, -): +) -> None: pb = os.path.join(config_instance.scenario.directory, "side_effect.yml") # noqa: PTH118 util.write_file(pb, "") se = side_effect.SideEffect(config_instance) - se.execute() # type: ignore[no-untyped-call] + se.execute() assert "default" in caplog.text assert "side_effect" in caplog.text @@ -75,13 +82,13 @@ def test_side_effect_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D _patched_ansible_side_effect.assert_called_once_with(None) -def test_side_effect_execute_skips_when_playbook_not_configured( # type: ignore[no-untyped-def] # noqa: ANN201, D103 - caplog, # noqa: ANN001 - _patched_ansible_side_effect, # noqa: ANN001, PT019 +def test_side_effect_execute_skips_when_playbook_not_configured( # noqa: D103 + caplog: pytest.LogCaptureFixture, + _patched_ansible_side_effect: Mock, # noqa: PT019 config_instance: config.Config, -): +) -> None: se = side_effect.SideEffect(config_instance) - se.execute() # type: ignore[no-untyped-call] + se.execute() msg = "Skipping, side effect playbook not configured." assert msg in caplog.text diff --git a/tests/unit/command/test_syntax.py b/tests/unit/command/test_syntax.py index 38a61a9e2..0ec21629e 100644 --- a/tests/unit/command/test_syntax.py +++ b/tests/unit/command/test_syntax.py @@ -27,28 +27,30 @@ if TYPE_CHECKING: + from unittest.mock import MagicMock, Mock + from pytest_mock import MockerFixture from molecule import config @pytest.fixture() -def _patched_ansible_syntax(mocker): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202 +def _patched_ansible_syntax(mocker: MockerFixture) -> MagicMock: return mocker.patch("molecule.provisioner.ansible.Ansible.syntax") # 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_syntax_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D103 +def test_syntax_execute( # noqa: D103 mocker: MockerFixture, # noqa: ARG001 - caplog, # noqa: ANN001 - _patched_ansible_syntax, # noqa: ANN001, PT019 - patched_config_validate, # noqa: ANN001, ARG001 + caplog: pytest.LogCaptureFixture, + _patched_ansible_syntax: Mock, # noqa: PT019 + patched_config_validate: Mock, # noqa: ARG001 config_instance: config.Config, -): +) -> None: s = syntax.Syntax(config_instance) - s.execute() # type: ignore[no-untyped-call] + s.execute() assert "default" in caplog.text assert "syntax" in caplog.text diff --git a/tests/unit/command/test_verify.py b/tests/unit/command/test_verify.py index b188512ea..4efca710f 100644 --- a/tests/unit/command/test_verify.py +++ b/tests/unit/command/test_verify.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_verify_execute( # type: ignore[no-untyped-def] # noqa: ANN201, D103 +def test_verify_execute( # noqa: D103 mocker: MockerFixture, # noqa: ARG001 - caplog, # noqa: ANN001 - patched_default_verifier, # noqa: ANN001, ARG001 - patched_config_validate, # noqa: ANN001, ARG001 + caplog: pytest.LogCaptureFixture, + patched_default_verifier: Mock, # noqa: ARG001 + patched_config_validate: Mock, # noqa: ARG001 config_instance: config.Config, -): +) -> None: v = verify.Verify(config_instance) - v.execute() # type: ignore[no-untyped-call] + v.execute() assert "default" in caplog.text assert "verify" in caplog.text