Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port unittests.mock package #11

Open
naftaliharris opened this issue Oct 31, 2016 · 5 comments
Open

Port unittests.mock package #11

naftaliharris opened this issue Oct 31, 2016 · 5 comments

Comments

@naftaliharris
Copy link
Owner

No description provided.

@naftaliharris
Copy link
Owner Author

Hmm, actually there is a private backport at Lib/test/_mock_backport.py...

@naftaliharris
Copy link
Owner Author

...but it doesn't work very well since it's still missing inspect.signature:

>>> import test._mock_backport as mock
>>> class Foo(object): pass
...
>>> mock.MagicMock(Foo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/naftali/repos/cpython/Lib/test/_mock_backport.py", line 1789, in __init__
    _safe_super(MagicMixin, self).__init__(*args, **kw)
  File "/Users/naftali/repos/cpython/Lib/test/_mock_backport.py", line 895, in __init__
    _spec_state, _new_name, _new_parent, **kwargs
  File "/Users/naftali/repos/cpython/Lib/test/_mock_backport.py", line 400, in __init__
    self._mock_add_spec(spec, spec_set, _spec_as_instance, _eat_self)
  File "/Users/naftali/repos/cpython/Lib/test/_mock_backport.py", line 457, in _mock_add_spec
    _spec_as_instance, _eat_self)
  File "/Users/naftali/repos/cpython/Lib/test/_mock_backport.py", line 100, in _get_signature_object
    return func, inspect.signature(sig_func)
AttributeError: 'module' object has no attribute 'signature'
>>>

@naftaliharris
Copy link
Owner Author

Diffing test._mock_backport and the unittest.mock in 3.5.2 shows that the 2.7 mock looks pretty good. Major substantial differences is a "visited" argument in reset_mock to prevent cycles, looks like a bugfix.

@naftaliharris
Copy link
Owner Author

Needs #14

@adamchainz
Copy link

Unnecessary as this exists: https://pypi.python.org/pypi/backports.unittest_mock/1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants