Search code examples
djangopytestcode-coveragedjango-testingcoverage.py

coverage showing 100% for settings.py file


I'm confused with coverage report which is generated with help of pytest. Here is my coverage html report.

Coverage HTML report

settings.py file is showing 100% covered, not sure how it is.. ?

Also, the following Loginform also shown as covered so I have added another dummy form even it is showing covered.

Django form wrongly shown as test covered

I'm facing difficulty in understanding this, though I don't have any tests added for settings or for the above forms it's showing as 100% covered, with this I'm not confident whether my code is properly tested or not.


Solution

  • Coverage.py can only tell you whether a line of code has been executed. Your form lines define a class. Those lines are executed when the file is imported. Coverage can't tell you whether some other code used that class or not. Same for your settings file. As soon as the file is imported, all of your settings assignments are executed, as coverage is telling you. Coverage can't tell you whether a setting was used.