|
8 | 8 |
|
9 | 9 | __version__ = version
|
10 | 10 |
|
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 |
| - |
17 | 11 |
|
18 | 12 | def _get_mock_module(config):
|
19 | 13 | """
|
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 |
22 | 16 | the mock_use_standalone_module ini option.
|
23 | 17 | """
|
24 | 18 | if not hasattr(_get_mock_module, "_module"):
|
25 | 19 | use_standalone_module = parse_ini_boolean(
|
26 | 20 | config.getini("mock_use_standalone_module")
|
27 | 21 | )
|
28 |
| - if sys.version_info[0] == 2 or use_standalone_module: |
| 22 | + if use_standalone_module: |
29 | 23 | import mock
|
30 | 24 |
|
31 | 25 | _get_mock_module._module = mock
|
@@ -103,13 +97,7 @@ def spy(self, obj, name):
|
103 | 97 | if isinstance(value, (classmethod, staticmethod)):
|
104 | 98 | autospec = False
|
105 | 99 |
|
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) |
113 | 101 | def wrapper(*args, **kwargs):
|
114 | 102 | try:
|
115 | 103 | r = method(*args, **kwargs)
|
@@ -226,21 +214,21 @@ def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
|
226 | 214 | return
|
227 | 215 | except AssertionError as e:
|
228 | 216 | if getattr(e, "_mock_introspection_applied", 0):
|
229 |
| - msg = text_type(e) |
| 217 | + msg = str(e) |
230 | 218 | else:
|
231 | 219 | __mock_self = args[0]
|
232 |
| - msg = text_type(e) |
| 220 | + msg = str(e) |
233 | 221 | if __mock_self.call_args is not None:
|
234 | 222 | actual_args, actual_kwargs = __mock_self.call_args
|
235 | 223 | introspection = ""
|
236 | 224 | try:
|
237 | 225 | assert actual_args == args[1:]
|
238 | 226 | except AssertionError as e:
|
239 |
| - introspection += "\nArgs:\n" + text_type(e) |
| 227 | + introspection += "\nArgs:\n" + str(e) |
240 | 228 | try:
|
241 | 229 | assert actual_kwargs == kwargs
|
242 | 230 | except AssertionError as e:
|
243 |
| - introspection += "\nKwargs:\n" + text_type(e) |
| 231 | + introspection += "\nKwargs:\n" + str(e) |
244 | 232 |
|
245 | 233 | if introspection:
|
246 | 234 | msg += "\n\npytest introspection follows:\n" + introspection
|
@@ -331,7 +319,7 @@ def unwrap_assert_methods():
|
331 | 319 | # so we need to catch this error here and ignore it;
|
332 | 320 | # unfortunately there's no public API to check if a patch
|
333 | 321 | # 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": |
335 | 323 | pass
|
336 | 324 | else:
|
337 | 325 | raise
|
|
0 commit comments