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

Try to import "mock" before "unittest.mock" #54

Merged
merged 1 commit into from
Jun 10, 2016

Conversation

wcooley
Copy link
Contributor

@wcooley wcooley commented Jun 10, 2016

I have hit a bug in mock that is fixed in the version of mock included
with Python 3.5.1 but present in 3.3.5 (fixed indirectly in
testing-cabal/mock@eba505cf3e). I can install the fixed "mock" package from
PyPI, but because pytest_mock only uses unittest.mock for Python
3.3+, the fixed package has no effect.

Instead of trying to check versions, I take the EAFP approach and just
try to import mock and fall back to unittest.mock. It is possible
that an old version of "mock" could be installed with a newer Python,
but that seems easier to fix than the reverse.

I have hit a bug in mock that is fixed in the version of mock included
with Python 3.5.1 but present in 3.3.5 (fixed indirectly in
testing-cabal/mock@eba505cf3e). I can install the fixed "mock" package from
PyPI, but because `pytest_mock` only uses `unittest.mock` for Python
3.3+, the fixed package has no effect.

Instead of trying to check versions, I take the EAFP approach and just
try to import `mock` and fall back to `unittest.mock`. It is possible
that an old version of "mock" could be installed with a newer Python,
but that seems easier to fix than the reverse.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 861f9e8 on wcooley:feature/allow-local-mock into a1cba1d on pytest-dev:master.

@nicoddemus nicoddemus merged commit 861f9e8 into pytest-dev:master Jun 10, 2016
nicoddemus added a commit that referenced this pull request Jun 10, 2016
@nicoddemus
Copy link
Member

Thanks for the PR! 😄

@wcooley wcooley deleted the feature/allow-local-mock branch June 14, 2016 21:58
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.

3 participants