Skip to content

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.

3 participants