From e2acbf147d37740effe184e1b211e73096b0c10b Mon Sep 17 00:00:00 2001
From: Sorin Sbarnea <ssbarnea@redhat.com>
Date: Mon, 3 Jul 2023 18:28:35 +0100
Subject: [PATCH] More types (#3955)

---
 src/molecule/test/a_unit/command/test_base.py      |  2 +-
 .../test/a_unit/command/test_idempotence.py        | 14 ++++++++------
 src/molecule/test/a_unit/dependency/test_shell.py  |  4 ++--
 src/molecule/test/a_unit/test_config.py            |  6 +++---
 src/molecule/test/a_unit/test_util.py              |  8 ++++----
 src/molecule/test/a_unit/verifier/test_ansible.py  |  2 +-
 src/molecule/util.py                               |  2 +-
 7 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/src/molecule/test/a_unit/command/test_base.py b/src/molecule/test/a_unit/command/test_base.py
index 39cd4dc7d5..2414602b9f 100644
--- a/src/molecule/test/a_unit/command/test_base.py
+++ b/src/molecule/test/a_unit/command/test_base.py
@@ -317,7 +317,7 @@ def test_verify_configs_raises_with_no_configs(caplog):
 
 
 def test_verify_configs_raises_with_duplicate_configs(
-    caplog,
+    caplog: pytest.LogCaptureFixture,
     config_instance: config.Config,
 ):
     with pytest.raises(SystemExit) as e:
diff --git a/src/molecule/test/a_unit/command/test_idempotence.py b/src/molecule/test/a_unit/command/test_idempotence.py
index 55d71feb60..181b51bc7c 100644
--- a/src/molecule/test/a_unit/command/test_idempotence.py
+++ b/src/molecule/test/a_unit/command/test_idempotence.py
@@ -18,6 +18,8 @@
 #  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 #  DEALINGS IN THE SOFTWARE.
 
+from unittest.mock import Mock
+
 import pytest
 from pytest_mock import MockerFixture
 
@@ -26,7 +28,7 @@
 
 
 @pytest.fixture()
-def _patched_is_idempotent(mocker):
+def _patched_is_idempotent(mocker: MockerFixture) -> Mock:
     return mocker.patch("molecule.command.idempotence.Idempotence._is_idempotent")
 
 
@@ -42,9 +44,9 @@ def _instance(patched_config_validate, config_instance: config.Config):
 
 def test_execute(
     mocker: MockerFixture,
-    caplog,
+    caplog: pytest.LogCaptureFixture,
     patched_ansible_converge,
-    _patched_is_idempotent,
+    _patched_is_idempotent: Mock,
     _instance,
 ):
     _instance.execute()
@@ -61,7 +63,7 @@ def test_execute(
 
 
 def test_execute_raises_when_not_converged(
-    caplog,
+    caplog: pytest.LogCaptureFixture,
     patched_ansible_converge,
     _instance,
 ):
@@ -77,9 +79,9 @@ def test_execute_raises_when_not_converged(
 
 def test_execute_raises_when_fails_idempotence(
     mocker: MockerFixture,
-    caplog,
+    caplog: pytest.LogCaptureFixture,
     patched_ansible_converge,
-    _patched_is_idempotent,
+    _patched_is_idempotent: Mock,
     _instance,
 ):
     _patched_is_idempotent.return_value = False
diff --git a/src/molecule/test/a_unit/dependency/test_shell.py b/src/molecule/test/a_unit/dependency/test_shell.py
index 3098a6c8b1..9533b7f9b2 100644
--- a/src/molecule/test/a_unit/dependency/test_shell.py
+++ b/src/molecule/test/a_unit/dependency/test_shell.py
@@ -95,7 +95,7 @@ def test_env_property(_instance):
     assert _instance.env["FOO"] == "bar"
 
 
-def test_execute(patched_run_command, caplog, _instance):
+def test_execute(patched_run_command, caplog: pytest.LogCaptureFixture, _instance):
     _instance._sh_command = "patched-command"
     _instance.execute()
 
@@ -111,7 +111,7 @@ def test_execute(patched_run_command, caplog, _instance):
 
 def test_execute_does_not_execute_when_disabled(
     patched_run_command,
-    caplog,
+    caplog: pytest.LogCaptureFixture,
     _instance,
 ):
     _instance._config.config["dependency"]["enabled"] = False
diff --git a/src/molecule/test/a_unit/test_config.py b/src/molecule/test/a_unit/test_config.py
index 0ca50bcbf6..438f52918c 100644
--- a/src/molecule/test/a_unit/test_config.py
+++ b/src/molecule/test/a_unit/test_config.py
@@ -176,7 +176,7 @@ def test_get_driver_name(config_instance: config.Config):
 
 
 def test_get_driver_name_raises_when_different_driver_used(
-    caplog,
+    caplog: pytest.LogCaptureFixture,
     config_instance: config.Config,
 ):
     config_instance.state.change_state("driver", "foo")
@@ -266,7 +266,7 @@ def test_interpolate_curly_default_variable(config_instance: config.Config):
 
 
 def test_interpolate_raises_on_failed_interpolation(
-    caplog,
+    caplog: pytest.LogCaptureFixture,
     config_instance: config.Config,
 ):
     string = "$6$8I5Cfmpr$kGZB"
@@ -311,7 +311,7 @@ def test_validate(
 
 def test_validate_exists_when_validation_fails(
     mocker: MockerFixture,
-    caplog,
+    caplog: pytest.LogCaptureFixture,
     config_instance: config.Config,
 ):
     m = mocker.patch("molecule.model.schema_v3.validate")
diff --git a/src/molecule/test/a_unit/test_util.py b/src/molecule/test/a_unit/test_util.py
index a7637662dd..bb4739dbb4 100644
--- a/src/molecule/test/a_unit/test_util.py
+++ b/src/molecule/test/a_unit/test_util.py
@@ -45,7 +45,7 @@ def test_print_debug():
     assert result == expected
 
 
-def test_print_environment_vars(capsys):
+def test_print_environment_vars(capsys: pytest.CaptureFixture[str]) -> None:
     env = {
         "ANSIBLE_FOO": "foo",
         "ANSIBLE_BAR": "bar",
@@ -86,7 +86,7 @@ def test_sysexit_with_custom_code():
     assert e.value.code == 2
 
 
-def test_sysexit_with_message(caplog):
+def test_sysexit_with_message(caplog: pytest.LogCaptureFixture):
     with pytest.raises(SystemExit) as e:
         util.sysexit_with_message("foo")
 
@@ -95,7 +95,7 @@ def test_sysexit_with_message(caplog):
     assert "foo" in caplog.text
 
 
-def test_sysexit_with_warns(caplog):
+def test_sysexit_with_warns(caplog: pytest.LogCaptureFixture):
     with pytest.raises(SystemExit) as e:
         with warnings.catch_warnings(record=True) as warns:
             warnings.filterwarnings("default", category=MoleculeRuntimeWarning)
@@ -109,7 +109,7 @@ def test_sysexit_with_warns(caplog):
     assert "xxx" in caplog.text
 
 
-def test_sysexit_with_message_and_custom_code(caplog):
+def test_sysexit_with_message_and_custom_code(caplog: pytest.LogCaptureFixture):
     with pytest.raises(SystemExit) as e:
         util.sysexit_with_message("foo", 2)
 
diff --git a/src/molecule/test/a_unit/verifier/test_ansible.py b/src/molecule/test/a_unit/verifier/test_ansible.py
index 1c8d371ccf..3ebda22784 100644
--- a/src/molecule/test/a_unit/verifier/test_ansible.py
+++ b/src/molecule/test/a_unit/verifier/test_ansible.py
@@ -94,7 +94,7 @@ def test_execute(caplog, _patched_ansible_verify, _instance):
 
 def test_execute_does_not_execute(
     patched_ansible_converge,
-    caplog,
+    caplog: pytest.LogCaptureFixture,
     _instance,
 ):
     _instance._config.config["verifier"]["enabled"] = False
diff --git a/src/molecule/util.py b/src/molecule/util.py
index 9547604d19..f408052ad3 100644
--- a/src/molecule/util.py
+++ b/src/molecule/util.py
@@ -55,7 +55,7 @@ def print_debug(title: str, data: str) -> None:
     console.print(f"DEBUG: {title}:\n{data}")
 
 
-def print_environment_vars(env: Optional[dict[str, str]]) -> None:
+def print_environment_vars(env: Optional[dict[str, Optional[str]]]) -> None:
     """Print ``Ansible`` and ``Molecule`` environment variables and returns None.
 
     :param env: A dict containing the shell's environment as collected by