"Plugin 'pytest_cov' could not be loaded" using Miniconda 2

I have a python repository with travis ci integration which installs the dependencies, code and runs tests using py.test on both python 3.6+ and python 2.7, for a while. Recently the tests broke (without code changes), and I replaced py.test calls by pytest and got the 3.6 version working. However, I am unable to get the python 2.7 version working: Some of the variations I tried:

  • even after adding a pytest to pip-requirements pinning the version to <3.3.0.
  • trying py.test instead.
  • increasing the install time (should not have worked).

The error I get is : https://travis-ci.com/LSSTDESC/OpSimSummary/builds/121299634?utm_medium=notification&utm_source=email

Traceback (most recent call last):
  File "/home/travis/miniconda/bin/py.test", line 10, in <module>
    sys.exit(main())
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/config.py", line 49, in main
    config = _prepareconfig(args, plugins)
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/config.py", line 168, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 250, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/helpconfig.py", line 68, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 280, in get_result
    _reraise(*ex)  # noqa
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
    self.result = func()
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/config.py", line 957, in pytest_cmdline_parse
    self.parse(args)
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/config.py", line 1121, in parse
    self._preparse(args, addopts=addopts)
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/config.py", line 1084, in _preparse
    self.pluginmanager.load_setuptools_entrypoints('pytest11')
  File "/home/travis/miniconda/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 515, in load_setuptools_entrypoints
    "Plugin %r could not be loaded: %s!" % (ep.name, e))
_pytest.vendored_packages.pluggy.PluginValidationError: Plugin 'pytest_cov' could not be loaded: (pytest 3.2.5 (/home/travis/miniconda/lib/python2.7/site-packages), Requirement.parse('pytest>=3.6'))!
The command "py.test tests" exited with 1.```
  
An obvious solution is to stop supporting Python 2.7, but I was wondering if there could be a different solution.

From what I can see, you never activate conda environment, nor are you deactivating the virtualenv preactivated by Travis. So God only knows which Python environment any of your installations end up in.

Please recheck your build logic and make sure you understand what each step does – only then can you fix it meaningfully. That’s because I see lots of redundant logic.

You can use Using conda with Travis CI — conda documentation as reference implementation.

Since you aren’t actually using Travis-provided Python, you can use language: generic to simplify the setup.

Your builds got migrated from our Trusty image to Xenial.

You’ll be able to get back to Trusty (and hopefully on the green side) by adding dist: trusty to your .travis.yml file.

See the following blog post for more details: https://blog.travis-ci.com/2019-04-15-xenial-default-build-environment.

Thanks for your comments.

From what I can see, you never activate conda environment, nor are you deactivating the virtualenv preactivated by Travis. So God only knows which Python environment any of your installations end up in.

I don’t use a conda environment. But does not

export PATH="$HOME/miniconda/bin:$PATH"

make this use the conda distribution I downloaded and built for python? So, I am a bit confused about why this should not be the python I am using.

Please recheck your build logic and make sure you understand what each step does – only then can you fix it meaningfully. That’s because I see lots of redundant logic.

I am not sure I know which ones are redundant … I did follow the Using conda with Travis CI to a large extent. If you would be kind enough to point out the redundant steps, I would be interested in fixing them. Thanks in advance!

Thanks for pointing this out. I took your advice and added the dist: trusty line at the start, but that does not fix the problem:

I still get a failure at the py.test call (only in Python 2.7), python 3.6 works fine.
https://travis-ci.com/LSSTDESC/OpSimSummary/jobs/221897665

I’ve generated a diff between the last succeeding job and this one that you can inspect here:

https://www.diffchecker.com/WME6FP6P

It seems that your dependencies changed version in between. I would suggest pinning down your dependencies to the version of the succeeding build.

Some examples:

success vs failure
pytest-4.4.2 vs pytest-3.2.5
PyYAML-5.1 vs PyYAML-5.1.2
coverage-4.5.3 vs coverage-4.5.4
numpy-1.16.3 vs numpy-1.16.4
etc.

I ran into the same issue recently.

TLDR; pip install -U ... will update existing packages instead of erroring.

The underlying issue seems to be pytest-cov 's required version range for pytest being updated to >=3.6.0 . The trusty image comes with pytest 3.3.0 preinstalled and pip errors instead of updating the existing install.

Hard coding the dist would temporarily fix the issue, but dependencies could get out of sync again as preinstalled packages and dependencies change. To avoid this occurring again, the best fix is probably to force pip to upgrade existing dependencies.

Thanks @dominic . Using your differences, I pinned pytest to 3.2.5 rather than use < 3.3.0 and that helped. Thanks a lot ! The fixing PR is https://github.com/LSSTDESC/OpSimSummary/pull/298

2 Likes
Imprint