Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

python - Coverage.py warning: No data was collected. (no-data-collected)

I am trying to find the coverage using coverage module for a django project but gets

Coverage.py warning: No data was collected. (no-data-collected)

My project folder has src and tests folders.

When I run

coverage run -m pytest && coverage report

It produces a report with 100% coverage with the list of files inside the tests folder. Whereas when I run

coverage run --source=src -m pytest && coverage report

it says

Coverage.py warning: No data was collected. (no-data-collected)
No data to report.

When I try to give the source=src or include=src in the .coveragerc also the same warning occurs. The tests passes for all the above cases.

I want the coverage of the src folder. Is it because I am missing some path setting?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

coverage (used by pytest-cov) needs the tests folder to contain an __init__.py before it will collect any data.

I added __init__.py to the tests folder and then coverage collected the data as expected.

Refer to http://thomas-cokelaer.info/blog/2017/01/pytest-cov-collects-no-data-on-travis/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...