Skip to content

Commit

Permalink
Use the mock backport on Python 3.7
Browse files Browse the repository at this point in the history
Because mock.call.kwargs, i.e. the ability to examine
m.call_args.kwargs where m is a Mock or MagicMock, was introduced
in Python 3.8.

Currently it is only in test/test_git.py that any use of mocks
requires this, so I've put the conditional import logic to import
mock (the top-level package) rather than unittest.mock only there.

The mock library is added as a development (testing) dependency
only when the Python version is lower than 3.8, so it is not
installed when not needed.

This fixes a problem in the new tests of whether a shell is used,
and reported as used, in the Popen call in Git.execute. Those
just-introduced tests need this, to be able to use
mock_popen.call_args.kwargs on Python 3.7.
  • Loading branch information
EliahKagan committed Oct 2, 2023
1 parent da3460c commit 41294d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
black
coverage[toml]
ddt>=1.1.1, !=1.4.3
ddt >= 1.1.1, != 1.4.3
mock ; python_version < "3.8"
mypy
pre-commit
pytest
Expand Down
7 changes: 6 additions & 1 deletion test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
import subprocess
import sys
from tempfile import TemporaryDirectory, TemporaryFile
from unittest import mock, skipUnless
from unittest import skipUnless

if sys.version_info >= (3, 8):
from unittest import mock
else:
import mock # To be able to examine call_args.kwargs on a mock.

import ddt

Expand Down

0 comments on commit 41294d5

Please sign in to comment.