Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41294d5

Browse files
committed
Use the mock backport on Python 3.7
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.
1 parent da3460c commit 41294d5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

test-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
black
22
coverage[toml]
3-
ddt>=1.1.1, !=1.4.3
3+
ddt >= 1.1.1, != 1.4.3
4+
mock ; python_version < "3.8"
45
mypy
56
pre-commit
67
pytest

test/test_git.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
import subprocess
1414
import sys
1515
from tempfile import TemporaryDirectory, TemporaryFile
16-
from unittest import mock, skipUnless
16+
from unittest import skipUnless
17+
18+
if sys.version_info >= (3, 8):
19+
from unittest import mock
20+
else:
21+
import mock # To be able to examine call_args.kwargs on a mock.
1722

1823
import ddt
1924

0 commit comments

Comments
 (0)