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

Fix mock patchings detection when both mock and unittest.mock are present #3206

merged 1 commit into from Feb 15, 2018


None yet
3 participants

mbachry commented Feb 12, 2018

If pypi mock package is installed and imported at any time during test run, it's impossible to use Python 3 @unittest.mock.patch(...) decorator. Mock object argument is not recognized by pytest with error like this:

      def test_hello(self, abspath):
E       fixture 'abspath' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_xml_attribute, record_xml_property, recwarn, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

It's often not possible to go with unittest.mock only, as pypi mock can be implicitly pulled by one of project dependencies. In my case, it's moto package.


This comment has been minimized.

coveralls commented Feb 12, 2018

Coverage Status

Coverage increased (+0.0008%) to 92.633% when pulling b6166dc on mbachry:fix-unittest-mock into e7bcc85 on pytest-dev:master.


This comment has been minimized.


nicoddemus commented Feb 15, 2018

Thanks a lot @mbachry!

@nicoddemus nicoddemus merged commit 371eb8c into pytest-dev:master Feb 15, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment