Coverage fails in tox file

We use SonarCloud - Github with Github Actions.
Our repository : Python , pytest

For getting test coverage properly I used the build.yml as suggested here. I only edited the tox.ini file and .properties file. But I have problem for tox file:

envlist = py39
skipsdist = True
deps =
commands = pytest --cov={my project name} --cov-report=xml --cov-config=tox.ini --cov-branch

However, when it is executed on Github Actions, I get the error below:

py: install_deps> python -I -m pip install coverage pytest

py: freeze> python -m pip freeze --all


py: commands[0]> pytest --cov={my project name} --cov-report=xml --cov-config=tox.ini --cov-branch

ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] […]

pytest: error: unrecognized arguments: --cov={my project name} --cov-report=xml --cov-config=tox.ini --cov-branch

inifile: None

rootdir: /home/runner/work/{my project name}/{my project name}

py: exit 4 (0.19 seconds) /home/runner/work/{my project name}/{my project name}> pytest --cov={my project name} --cov-report=xml --cov-config=tox.ini --cov-branch pid=1977

py: FAIL code 4 (3.40=setup[3.21]+cmd[0.19] seconds)

evaluation failed :frowning: (3.46 seconds)

Error: Process completed with exit code 4.

  1. How can I solve this issue?
  2. What is the correct way to write project name? {organisation name}-{project name}?
  3. What should be written for pytest attributes?:
  • –cov=
  • –cov-report=
  • –cov-config=
  • –cov-branch=

Hi @Furkan_YY,

Thanks for reporting this, we created a ticket for this and we’ll update this page soon.

Hi @Furkan_YY ,
I think there is indeed a mistake in the documentation.
The tox file should declare pytest-cov as dependency in order to be able to use --cov related arguments.

envlist = py39
skipsdist = True
deps =
    pytest-cov # <---- changed here
commands = pytest --cov={my project name} --cov-report=xml --cov-config=tox.ini --cov-branch

What should be written for pytest attributes?

--cov should refer to the entry point package of your python project.
--cov-report should be xml
--cov-config should point to the tox file
--cov-branch : no value needed, just need to be enabled.

You can have a look at this example: python-demo-project/tox.ini at main · andreaguarino/python-demo-project · GitHub

Hope it helps,
Andrea G.