How do you measure and improve test coverage in a Django project? Django प्रोजेक्ट में टेस्ट कवरेज को कैसे मापें और बेहतर बनाएं?
The coverage.py library, run alongside Django's test suite (coverage run manage.py test), tracks which lines of source code were actually executed during the test run, and coverage report/coverage html produce a summary showing the percentage of covered lines per file, highlighting exactly which lines were never exercised by any test.
High coverage doesn't guarantee correctness — a test can execute a line without actually asserting anything meaningful about its behavior — so coverage is best treated as a tool for finding untested code paths (especially error-handling branches and edge cases that are easy to forget) rather than a target number to chase for its own sake. CI pipelines commonly enforce a minimum coverage threshold to prevent untested code from being merged.
# Run tests with coverage tracking
coverage run --source='.' manage.py test
coverage report -m
coverage html # generates browsable HTML reportcoverage.py लाइब्रेरी, जो Django के टेस्ट सूट के साथ चलती है, ट्रैक करती है कि टेस्ट रन के दौरान सोर्स कोड की कौन-सी लाइनें वास्तव में चलीं, और coverage report प्रति फाइल कवर की गई लाइनों का प्रतिशत दिखाने वाला सारांश तैयार करता है।
उच्च कवरेज सटीकता की गारंटी नहीं देता — एक टेस्ट किसी लाइन को चला सकता है बिना उसके व्यवहार के बारे में वास्तव में कुछ सार्थक एसर्ट किए — इसलिए कवरेज को अनटेस्टेड कोड पथों को खोजने के लिए एक उपकरण के रूप में देखा जाना चाहिए।
coverage run --source='.' manage.py test
coverage report -m
coverage htmlWas this answer clear?