-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Prefer unittest.mock before mock #3612
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
Conversation
|
good reminder, needing mock is insane - good tests should do without |
| try: | ||
| import unittest.mock as mock | ||
| except ImportError: | ||
| import mock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are occasions where this is undesirable, for instance I'd prefer to use the backported mock (>=2) over the stdlib in python3.4:
$ python3.4 -c 'from unittest import mock; mock.Mock().assert_wat()'
$ python3.4 -c 'import mock; mock.Mock().assert_wat()'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/mock/mock.py", line 703, in __getattr__
raise AttributeError(name)
AttributeError: assert_watThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so first try import mock and with ImportError stdlib..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually more of a +0/-0 on this change -- this is part of the test suite for pytest and not part of the public package. pytest also hard codes a test dependency on mock so the import should never fail under normal circumstances
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm with @asottile, but @RonnyPfannschmidt seems to be +1 about it.
From Python 3.3 is mock part of python standard library in unittest namespace
|
@asottile @nicoddemus so I changed logic to try import first upstream |
From Python 3.3 is mock part of python standard library in unittest namespace
AUTHORSin alphabetical order;