Pytest coverage in Docker container

Hi all,

I’d like to run the coverage of my application which uses the stable image of FEniCS with pytest.

I tried the following:

pip3 install pytest-cov
pytest-3 --cov

This results in the error below:

  File "/usr/lib/python3/dist-packages/pluggy/__init__.py", line 397, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py", line 2442, in load
    self.require(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py", line 2465, in require
    items = working_set.resolve(reqs, env, installer, extras=self.extras)
  File "/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py", line 791, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pytest 3.3.2 (/usr/lib/python3/dist-packages), Requirement.parse('pytest>=3.6'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/pytest-3", line 11, in <module>
    load_entry_point('pytest==3.3.2', 'console_scripts', 'pytest')()
  File "/usr/lib/python3/dist-packages/_pytest/config.py", line 50, in main
    config = _prepareconfig(args, plugins)
  File "/usr/lib/python3/dist-packages/_pytest/config.py", line 160, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/usr/lib/python3/dist-packages/pluggy/__init__.py", line 617, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/usr/lib/python3/dist-packages/pluggy/__init__.py", line 222, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/lib/python3/dist-packages/pluggy/__init__.py", line 216, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "/usr/lib/python3/dist-packages/pluggy/callers.py", line 196, in _multicall
    gen.send(outcome)
  File "/usr/lib/python3/dist-packages/_pytest/helpconfig.py", line 68, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/lib/python3/dist-packages/pluggy/callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3/dist-packages/pluggy/callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3/dist-packages/_pytest/config.py", line 943, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/lib/python3/dist-packages/_pytest/config.py", line 1108, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/lib/python3/dist-packages/_pytest/config.py", line 1071, in _preparse
    self.pluginmanager.load_setuptools_entrypoints('pytest11')
  File "/usr/lib/python3/dist-packages/pluggy/__init__.py", line 402, in load_setuptools_entrypoints
    "Plugin %r could not be loaded: %s!" % (ep.name, e))
pluggy.PluginValidationError: Plugin 'pytest_cov' could not be loaded: (pytest 3.3.2 (/usr/lib/python3/dist-packages), Requirement.parse('pytest>=3.6'))!

Thanks for the help!

As the error quite clarely stated, you Need to update pytest.
pip3 install pytest —upgrade
Should do the trick.

pip3 install --upgrade pytest
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: pytest in /home/fenics/.local/lib/python3.6/site-packages (5.4.2)
Requirement already satisfied, skipping upgrade: packaging in /home/fenics/.local/lib/python3.6/site-packages (from pytest) (20.3)
Requirement already satisfied, skipping upgrade: pluggy<1.0,>=0.12 in /home/fenics/.local/lib/python3.6/site-packages (from pytest) (0.13.1)
Requirement already satisfied, skipping upgrade: attrs>=17.4.0 in /usr/lib/python3/dist-packages (from pytest) (17.4.0)
Requirement already satisfied, skipping upgrade: py>=1.5.0 in /usr/lib/python3/dist-packages (from pytest) (1.5.2)
Requirement already satisfied, skipping upgrade: more-itertools>=4.0.0 in /usr/local/lib/python3.6/dist-packages (from pytest) (8.0.2)
Requirement already satisfied, skipping upgrade: wcwidth in /usr/local/lib/python3.6/dist-packages (from pytest) (0.1.8)
Requirement already satisfied, skipping upgrade: importlib-metadata>=0.12; python_version < "3.8" in /usr/local/lib/python3.6/dist-packages (from pytest) (1.3.0)
Requirement already satisfied, skipping upgrade: pyparsing>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from packaging->pytest) (2.4.6)
Requirement already satisfied, skipping upgrade: six in /usr/lib/python3/dist-packages (from packaging->pytest) (1.11.0)
Requirement already satisfied, skipping upgrade: zipp>=0.5 in /usr/local/lib/python3.6/dist-packages (from importlib-metadata>=0.12; python_version < "3.8"->pytest) (0.6.0)

But the same error remains

Could you try the following:

python3 -m pytest  --cov-report

It seems like there are multiple pips available in the docker image. However, this should use the one used with pip3.

This worked thank you very much!