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

Do not fallback when importing "unittest.mock" #68

Closed
nicoddemus opened this issue Nov 1, 2016 · 0 comments
Closed

Do not fallback when importing "unittest.mock" #68

nicoddemus opened this issue Nov 1, 2016 · 0 comments

Comments

@nicoddemus
Copy link
Member

nicoddemus commented Nov 1, 2016

try:
    import mock as mock_module
except ImportError:
    import unittest.mock as mock_module

Use this instead:

if sys.version_info.major == 2:
    import mock as mock_module
else:
    import unittest.mock as mock_module

This way we don't "swallow" the first exception in Python 2 in case something goes wrong when importing mock.

EDIT: Just for the record, the first import mock as mock_module was raising an ImportError but not because mock was missing, one of its dependencies was not installed (it was a frozen application). This made this problem much harder to debug.

cc @gqmelo

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

1 participant