pytest因ModuleNotFoundError和未使用插件的名称而失败

时间:2017-10-25 04:07:52

标签: travis-ci pytest conda python-hypothesis

我维护一个开源库xarray,它使用pytest在Travis-CI上运行集成测试。我们使用stack conda安装科学Python。

Earlier today,我们的五个测试版本中的两个(Python 3.5和3.6,但不是Python 2.7或3.4)开始失败,没有明显的原因。 pytest本身失败了,带着神秘的引用:

$ py.test xarray --cov=xarray --cov-config ci/.coveragerc --cov-report term-missing --verbose $EXTRA_FLAGS
Traceback (most recent call last):
  File "/home/travis/miniconda/envs/test_env/bin/py.test", line 6, in <module>
    sys.exit(py.test.main())
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/config.py", line 49, in main
    config = _prepareconfig(args, plugins)
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/config.py", line 168, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/vendored_packages/pluggy.py", line 250, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/helpconfig.py", line 68, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
    self.result = func()
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/config.py", line 957, in pytest_cmdline_parse
    self.parse(args)
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/config.py", line 1121, in parse
    self._preparse(args, addopts=addopts)
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/config.py", line 1084, in _preparse
    self.pluginmanager.load_setuptools_entrypoints('pytest11')
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/_pytest/vendored_packages/pluggy.py", line 510, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2409, in load
    return self.resolve()
  File "/home/travis/miniconda/envs/test_env/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2415, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'hypothesis.extra.pytestplugin'

对我来说,有些事情让我感到惊讶:

  1. 我们不使用假设或安装hypothesis.extra.pytestplugin。我不知道这是从哪里来的。
  2. 没有明显的改变来触发此错误。它首先出现在one line doc change之后。已安装的Python库(包括conda安装的特定二进制版本)看起来完全相同。 (不过,如果您愿意,可以diff自己build outputs。)
  3. 如果您对正在发生的事情有任何线索或猜测,我们将非常感谢您的帮助!我甚至不知道在堆栈中哪里提交错误。

1 个答案:

答案 0 :(得分:2)

我挖了一下这个:

  • Conda forge为我们提供hypothesis: 3.33.0-py36_0pytest将其作为插件加载
  • hypothesis的conda版本固定到3.23可以解决问题。
  • 卸载假设解决了问题
  • Pip安装假设解决了这个问题

所以,我认为我们可以断定conda-forge建立假设的问题。

conda-forge页面上有一个未解决的问题:

https://github.com/conda-forge/hypothesis-feedstock/issues/16