simplistix/testfixtures

6.4.2 breaks with python 2.7

Closed this issue · 8 comments

Traceback:
pupils/tests/test_rest_api_internal_views.py:29: in <module>
    from testfixtures import LogCapture
../venv/lib/python2.7/site-packages/testfixtures/__init__.py:13: in <module>
    from testfixtures.comparison import (
../venv/lib/python2.7/site-packages/testfixtures/comparison.py:13: in <module>
    from testfixtures.mock import parent_name
../venv/lib/python2.7/site-packages/testfixtures/mock.py:23: in <module>
    from unittest.mock import *
E   ImportError: No module named mock

The tests run fine with 6.4.1

iham commented

same error here! python 2.7

6.4.1 is good

It looks like this is the commit that broke it: add392c#diff-675b9e021465554ab95bbe94fcf00018

And it wasn't caught by the travis testing because mock is explicitly installed in the test environment via the [test] tag in extras_require in setup.py (pip install -Ue .[test])

This seems like something that should be captured by requirements.txt? It's not clear to me why requirements.txt is including the [build] tag from the extras_require dict, isn't it supposed to include runtime dependencies?

Also this can be reproduced in a clean python2 virtualenv by simply trying to import testfixtures

same error, but deep in the dependency stack (since testfixtures is installed by a flake8 plugin):

ImportError: No module named mock
flake8.plugins.manager    MainProcess    191 CRITICAL Flake8 failed to load plugin "I00" due to No module named mock.
Traceback (most recent call last):
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/lib/python2.7/site-packages/flake8/main/application.py", line 412, in run
    self._run(argv)
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/lib/python2.7/site-packages/flake8/main/application.py", line 399, in _run
    self.initialize(argv)
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/lib/python2.7/site-packages/flake8/main/application.py", line 381, in initialize
    self.find_plugins()
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/lib/python2.7/site-packages/flake8/main/application.py", line 197, in find_plugins
    self.check_plugins.load_plugins()
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/lib/python2.7/site-packages/flake8/plugins/manager.py", line 434, in load_plugins
    plugins = list(self.manager.map(load_plugin))
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/lib/python2.7/site-packages/flake8/plugins/manager.py", line 319, in map
    yield func(self.plugins[name], *args, **kwargs)
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/lib/python2.7/site-packages/flake8/plugins/manager.py", line 432, in load_plugin
    return plugin.load_plugin()
  File "/Users/viggy/GitHub/curai/python/libs/common/.tox/py27/lib/python2.7/site-packages/flake8/plugins/manager.py", line 189, in load_plugin
    raise failed_to_load
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "I00" due to No module named mock.

Working around by pinning to 6.4.1 as suggested.

I'll be working on a fix for this, hopefully released tomorrow, but in the meantime, options are:

  • Why are you still on Python 2? ;-) You should be on Python 3 by now!
  • Install the mock backport
  • Go back to 6.4.1

testfixtures is not supposed to require the backport, so this is a bug, but enough of testfixtures own tests use mock that it's not practical to run a branch without it at all.

thanks @cjw296! we're working on upgrading 😄legacy code dies a slow death.

we predominantly use Python 3, but for libraries that we publish, we lint and test against 2.7 using tox, which is where we bumped into this. Anyone who uses flake8 plugins (I think flake8-isort is the culprit) together with Python 2.7 will likely encounter this. thanks again for the quick response!

Hopefully the 6.4.3 release containing d75616f will fix this.

Works for me! Thanks @cjw296