Skip to content

Conversation

@mimi1vx
Copy link
Contributor

@mimi1vx mimi1vx commented Jun 22, 2018

From Python 3.3 is mock part of python standard library in unittest namespace

  • Add yourself to AUTHORS in alphabetical order;

@RonnyPfannschmidt
Copy link
Member

good reminder, needing mock is insane - good tests should do without

@coveralls
Copy link

coveralls commented Jun 22, 2018

Coverage Status

Coverage increased (+0.05%) to 92.677% when pulling deff54a on mimi1vx:patch-1 into 50a0d4f on pytest-dev:master.

try:
import unittest.mock as mock
except ImportError:
import mock
Copy link
Member

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_wat

Copy link
Contributor Author

@mimi1vx mimi1vx Jun 23, 2018

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..

Copy link
Member

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

Copy link
Member

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
@mimi1vx
Copy link
Contributor Author

mimi1vx commented Jun 23, 2018

@asottile @nicoddemus so I changed logic to try import first upstream mock and if this fail stdlib unittest.mock

@RonnyPfannschmidt RonnyPfannschmidt merged commit 42b3125 into pytest-dev:master Jun 24, 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.

5 participants