# "Plugin 'pytest\_cov' could not be loaded" using Miniconda 2

**URL:** <https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465>\
**Category:** Python\
**Created:** [July 31, 2019, 5:07am UTC](https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465 "2019-07-31T05:07:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbiswas4](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@rbiswas4](https://travis-ci.community/u/rbiswas4)\
**Post date:** [July 31, 2019, 5:07am UTC](https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465/1 "2019-07-31T05:07:16Z")

</div>

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](https://travis-ci.com/LSSTDESC/OpSimSummary/builds/121299634?utm_medium=notification&utm_source=email)

````auto
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.
````

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [July 31, 2019, 5:48am UTC](https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465/2 "2019-07-31T05:48:59Z")

</div>

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](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/use-conda-with-travis-ci.html) as reference implementation.

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

---

<div class="post-metadata">

**Author:** ![dominic](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/dominic/32/14_2.png) [@dominic](https://travis-ci.community/u/dominic)\
**Post date:** [July 31, 2019, 3:08pm UTC](https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465/3 "2019-07-31T15:08:26Z")

</div>

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](https://blog.travis-ci.com/2019-04-15-xenial-default-build-environment).

---

<div class="post-metadata">

**Author:** ![rbiswas4](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@rbiswas4](https://travis-ci.community/u/rbiswas4)\
**Post date:** [August 2, 2019, 1:34pm UTC](https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465/4 "2019-08-02T13:34:56Z")

</div>

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

```auto
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!

>

---

<div class="post-metadata">

**Author:** ![rbiswas4](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@rbiswas4](https://travis-ci.community/u/rbiswas4)\
**Post date:** [August 2, 2019, 1:50pm UTC](https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465/5 "2019-08-02T13:50:56Z")

</div>

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](https://travis-ci.com/LSSTDESC/OpSimSummary/jobs/221897665)

---

<div class="post-metadata">

**Author:** ![dominic](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/dominic/32/14_2.png) [@dominic](https://travis-ci.community/u/dominic)\
**Post date:** [August 2, 2019, 2:16pm UTC](https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465/6 "2019-08-02T14:16:21Z")

</div>

I’ve generated a diff between [the last succeeding job](https://travis-ci.com/LSSTDESC/OpSimSummary/jobs/198862497) and [this one](https://travis-ci.com/LSSTDESC/OpSimSummary/jobs/221897665) that you can inspect here:

[https://www.diffchecker.com/WME6FP6P](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.

---

<div class="post-metadata">

**Author:** ![deckar01](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/deckar01/32/2457_2.png) [@deckar01](https://travis-ci.community/u/deckar01)\
**Post date:** [August 6, 2019, 7:11pm UTC](https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465/7 "2019-08-06T19:11:58Z")

</div>

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.

> <https://github.com/perrygeo/simanneal/issues/30>
>
> See https://travis-ci.org/perrygeo/simanneal/jobs/566946682 and #28

---

<div class="post-metadata">

**Author:** ![rbiswas4](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@rbiswas4](https://travis-ci.community/u/rbiswas4)\
**Post date:** [August 7, 2019, 2:06pm UTC](https://travis-ci.community/t/plugin-pytest-cov-could-not-be-loaded-using-miniconda-2/4465/8 "2019-08-07T14:06:52Z")

</div>

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](https://github.com/LSSTDESC/OpSimSummary/pull/298)
