Skip to content

Commit d6e1540

Browse files
committed
Drop support for EOL Python 2.7
1 parent 8e9ff03 commit d6e1540

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ Tests are run with ``tox``, you can run the baseline environments before submitt
334334

335335
.. code-block:: console
336336
337-
$ tox -e py27,py36,linting
337+
$ tox -e py38,linting
338338
339339
Style checks and formatting are done automatically during commit courtesy of
340340
`pre-commit <https://pre-commit.com>`_.

src/pytest_mock/plugin.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,18 @@
88

99
__version__ = version
1010

11-
# pseudo-six; if this starts to require more than this, depend on six already
12-
if sys.version_info[0] == 2: # pragma: no cover
13-
text_type = unicode # noqa
14-
else:
15-
text_type = str
16-
1711

1812
def _get_mock_module(config):
1913
"""
20-
Import and return the actual "mock" module. By default this is "mock" for Python 2 and
21-
"unittest.mock" for Python 3, but the user can force to always use "mock" on Python 3 using
14+
Import and return the actual "mock" module. By default this is
15+
"unittest.mock", but the user can force to always use "mock" using
2216
the mock_use_standalone_module ini option.
2317
"""
2418
if not hasattr(_get_mock_module, "_module"):
2519
use_standalone_module = parse_ini_boolean(
2620
config.getini("mock_use_standalone_module")
2721
)
28-
if sys.version_info[0] == 2 or use_standalone_module:
22+
if use_standalone_module:
2923
import mock
3024

3125
_get_mock_module._module = mock
@@ -103,13 +97,7 @@ def spy(self, obj, name):
10397
if isinstance(value, (classmethod, staticmethod)):
10498
autospec = False
10599

106-
if sys.version_info[0] == 2:
107-
assigned = [x for x in functools.WRAPPER_ASSIGNMENTS if hasattr(method, x)]
108-
w = functools.wraps(method, assigned=assigned)
109-
else:
110-
w = functools.wraps(method)
111-
112-
@w
100+
@functools.wraps(method)
113101
def wrapper(*args, **kwargs):
114102
try:
115103
r = method(*args, **kwargs)
@@ -226,21 +214,21 @@ def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
226214
return
227215
except AssertionError as e:
228216
if getattr(e, "_mock_introspection_applied", 0):
229-
msg = text_type(e)
217+
msg = str(e)
230218
else:
231219
__mock_self = args[0]
232-
msg = text_type(e)
220+
msg = str(e)
233221
if __mock_self.call_args is not None:
234222
actual_args, actual_kwargs = __mock_self.call_args
235223
introspection = ""
236224
try:
237225
assert actual_args == args[1:]
238226
except AssertionError as e:
239-
introspection += "\nArgs:\n" + text_type(e)
227+
introspection += "\nArgs:\n" + str(e)
240228
try:
241229
assert actual_kwargs == kwargs
242230
except AssertionError as e:
243-
introspection += "\nKwargs:\n" + text_type(e)
231+
introspection += "\nKwargs:\n" + str(e)
244232

245233
if introspection:
246234
msg += "\n\npytest introspection follows:\n" + introspection
@@ -331,7 +319,7 @@ def unwrap_assert_methods():
331319
# so we need to catch this error here and ignore it;
332320
# unfortunately there's no public API to check if a patch
333321
# has been started, so catching the error it is
334-
if text_type(e) == "stop called on unstarted patcher":
322+
if str(e) == "stop called on unstarted patcher":
335323
pass
336324
else:
337325
raise

tests/test_pytest_mock.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515

1616
# Python 3.8 changed the output formatting (bpo-35500), which has been ported to mock 3.0
17-
NEW_FORMATTING = sys.version_info >= (3, 8) or sys.version_info[0] == 2
17+
NEW_FORMATTING = sys.version_info >= (3, 8)
1818

1919

2020
@pytest.fixture
@@ -312,7 +312,6 @@ def bar(cls, arg):
312312

313313

314314
@skip_pypy
315-
@pytest.mark.xfail(sys.version_info[0] == 2, reason="does not work on Python 2")
316315
def test_class_method_subclass_spy(mocker):
317316
class Base:
318317
@classmethod
@@ -367,7 +366,6 @@ def bar(arg):
367366

368367

369368
@skip_pypy
370-
@pytest.mark.xfail(sys.version_info[0] == 2, reason="does not work on Python 2")
371369
def test_static_method_subclass_spy(mocker):
372370
class Base:
373371
@staticmethod
@@ -625,7 +623,6 @@ def test_foo(mocker):
625623
assert result.stdout.lines == []
626624

627625

628-
@pytest.mark.skipif(sys.version_info[0] < 3, reason="Py3 only")
629626
def test_standalone_mock(testdir):
630627
"""Check that the "mock_use_standalone" is being used.
631628
"""
@@ -797,7 +794,7 @@ def test_foo(mocker):
797794
result = testdir.runpytest()
798795
result.stdout.fnmatch_lines("* 1 passed *")
799796

800-
kwargs = {"legacy": True} if sys.version_info[0] >= 3 else {}
797+
kwargs = {"legacy": True}
801798
assert compileall.compile_file(str(py_fn), **kwargs)
802799

803800
pyc_fn = str(py_fn) + "c"

0 commit comments

Comments
 (0)