From abfb91fd7da34111828d81a20fe7aeaaab7a58c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Mon, 6 Nov 2023 13:29:21 +0100 Subject: [PATCH] Fix assertions in `test_git_hook` Fix `called_once()` assertions in `test_git_hook` to use the correct `assert_called_once()` method. The former does not exist, so it evaluates to a mocked method in Python < 3.12, making the assert meaningless, and it triggers an error in Python 3.12+. While at it, split the mock into two because otherwise the test would fail because two `hooks.git_hook()` calls imply two mock calls. --- tests/unit/test_hooks.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_hooks.py b/tests/unit/test_hooks.py index 2757f414f..29685f503 100644 --- a/tests/unit/test_hooks.py +++ b/tests/unit/test_hooks.py @@ -11,7 +11,7 @@ def test_git_hook(src_dir): # Ensure correct subprocess command is called with patch("subprocess.run", MagicMock()) as run_mock: hooks.git_hook() - assert run_mock.called_once() + run_mock.assert_called_once() assert run_mock.call_args[0][0] == [ "git", "diff-index", @@ -21,8 +21,9 @@ def test_git_hook(src_dir): "HEAD", ] + with patch("subprocess.run", MagicMock()) as run_mock: hooks.git_hook(lazy=True) - assert run_mock.called_once() + run_mock.assert_called_once() assert run_mock.call_args[0][0] == [ "git", "diff-index",