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

Bug/396 #397

Closed
wants to merge 2 commits into from
Closed

Bug/396 #397

wants to merge 2 commits into from

Conversation

claudiubelu
Copy link

No description provided.

Mock can accept an spec object / class as argument, making sure
that accessing attributes that do not exist in the spec will cause an
AttributeError to be raised, but there is no guarantee that the spec's
methods signatures are respected in any way. This creates the possibility
to have faulty code with passing unittests and assertions.

Adds the autospec argument to Mock, and its mock_add_spec method.

Passes the spec's attribute with the same name to the child mock (spec-ing
the child), if the mock's autospec is True.

Sets _mock_check_sig if the given spec is callable.

Adds unit tests to validate the fact that the autospec method signatures are
respected.
Currently, when patching methods with autospec, their self / cls
arguments are not consumed, causing call asserts to fail (they
expect an instance / class reference as the first argument).

When patching with autospec, a Mock object is created with the
given spec. Due to commit 47e8f38, the method signature will
be checked for Mock objects with spec objects. Thus, there is
no need to add another signature check on create_autospec.
@cjw296
Copy link
Collaborator

cjw296 commented Nov 29, 2018

Please look at getting this fixed in https://github.com/python/cpython, after that, we can backport to this repo.

@cjw296 cjw296 closed this Nov 29, 2018
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

Successfully merging this pull request may close these issues.

2 participants