use getattr_static in spy instead of __getattributes__#224
Merged
nicoddemus merged 4 commits intopytest-dev:masterfrom Jan 10, 2021
Merged
use getattr_static in spy instead of __getattributes__#224nicoddemus merged 4 commits intopytest-dev:masterfrom
nicoddemus merged 4 commits intopytest-dev:masterfrom
Conversation
yesthesoup
commented
Jan 7, 2021
tests/test_pytest_mock.py
Outdated
| ) | ||
| def test_mocker_aliases(name: str, pytestconfig: Any) -> None: | ||
| from pytest_mock.plugin import _get_mock_module | ||
| from pytest_mock.plugin import _get_mock_module # type: ignore |
Contributor
Author
There was a problem hiding this comment.
the pre-commit mypy run caught these imports with error: Cannot find implementation or library
but now the linting test is failing because of them...any ideas?
Member
There was a problem hiding this comment.
Not sure, but I've moved _get_mock_module and parse_ini_boolean to a _util.py module: this makes it clear this is not part of the API plus should fix that particular problem.
This also avoids having to use "#type:ignore" when importing them on tests.
Member
|
Awesome, thanks for the contribution! |
Member
|
Thanks again! |
Contributor
Author
Thanks for your help on this one! |
This was referenced Mar 12, 2021
1 task
1 task
Merged
1 task
1 task
1 task
1 task
1 task
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When attempting to use
mocker.spyon a Stripe class in my project, I ran into this error:Here is the Customer source code for reference, a class inheriting from multiple parent classes and including some custom method wrappers.
While digging in order to fix this, I ended up at the stackoverflow question linked to in the original code which mentioned the
inspectmodule's methodgetattr_staticavailable as of 3.2. This will accomplish the same behaviour as before, as well as work for a larger variety of classes.I also checked up on the bug that this workaround is there for in the first place, and it was fixed in 3.7 it seems, so eventually autospec can be true by default in theory.
I don't quite know how to reproduce the exact kind of class that would have caused this error in the first place, open to suggestions in order to add a test for it.