Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 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?

question from:https://stackoverflow.com/questions/47287721/coverage-py-warning-no-data-was-collected-no-data-collected

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

1 Reply

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...