Skip to content

Commit

Permalink
Fix assertions in test_git_hook
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mgorny committed Nov 6, 2023
1 parent 14d0b36 commit abfb91f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/unit/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit abfb91f

Please sign in to comment.