Lavínia Beghini
Lavínia Beghini

Reputation: 275

pytest does not find .coveragerc configs

I am trying to run pytest with coverage output, using a .coveragerc file.

First of all, here is my folder structure:

playground/
├─ excercise.01/
│  ├─ calculator.py
│  ├─ test_calculator.py
├─ .coveragerc

Then, inside the exercise.01 folder (as it contains my test) I tried to run:

pytest --cov-config=../.coveragerc

And it just gives me this output, without the coverage:

collected 2 items                                                                                                                                                                       

exercise.01\test_calculator.py ..  [100%] 

=========== 2 passed in 0.06s ===========

I tried to run at the root folder as well.

Here is the content of the .coveragerc:

[tool:pytest]
addopts = --cov --cov-branch --cov-fail-under=90 --cov-report html

[run]
omit = test_*

The desired output should be as follows:

collected 2 items                                                                                                                                                                       

exercise.01\test_calculator.py ..                              [100%] 

------- coverage: platform win32, python 3.9.13-final-0 --------
Coverage HTML written to dir htmlcov

FAIL Required test coverage of 90% not reached. Total coverage: 84.62%

========================= 2 passed in 0.38s =========================

I find this results running:

pytest --cov=exercise.01 --cov-branch --cov-fail-under=90 --cov-report html

Which is exactly the addopts found inside the .coveragerc file. That is why I know pytest cannot find the file .coveragerc

I wonder why it is not working?

Just to add some more information as it might be helpful, I am using Python 3.9.13 and this is what I have on my requirements.txt:

attrs==22.1.0
coverage==6.4.4
importlib-metadata==4.12.0
iniconfig==1.1.1
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.0.9
pytest==7.1.3
pytest-cov==3.0.0
tomli==2.0.1
typing_extensions==4.3.0
zipp==3.8.1

Upvotes: 1

Views: 1632

Answers (1)

Ned Batchelder
Ned Batchelder

Reputation: 375574

.coveragerc files don't accept [tool:pytest] sections. That's something that can go in a setup.cfg or pyproject.toml file. You are mixing syntaxes.

Upvotes: 2

Related Questions