How to run coverage for specific file

I’m in my project directory trying to test the coverage of my tests for utils.py using this command:
coverage run --source=app/utils.py -m pytest test_app/test_utils.py

I’m getting CoverageWarning messages saying utils was never imported and no data was collected. I don’t have a .coveragerc file in this project, so I’m confused why I can’t get coverage working.

@nedbat Can you help?

The docs for --source say “A list of directories or importable names of code to measure.” How do you import utils? Use that format with the argument. You can examine what coverage is doing by adding --debug=trace, which will log decisions being made about what to trace and what not to trace and why.

1 Like

Sorry for missing that. Thank you so much for the help!

coverage run --source=app.utils -m pytest test_app/test_utils.py