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

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

Merged
merged 1 commit into from
Feb 15, 2018

Conversation

mbachry
Copy link
Contributor

@mbachry 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:

      @unittest.mock.patch("os.path.abspath")
      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.

@coveralls
Copy link

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.

@nicoddemus
Copy link
Member

Thanks a lot @mbachry!

@nicoddemus nicoddemus merged commit 371eb8c into pytest-dev:master Feb 15, 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.

None yet

3 participants