0
0
Djangoframework~20 mins

Coverage reporting in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Coverage Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Understanding coverage report output in Django tests
You run Django tests with coverage enabled. The coverage report shows 85% coverage for your app. What does this 85% mean?
A85% of your app's database queries were tested.
B85% of your test cases passed successfully.
C85% of your Python code lines in the app were executed during tests.
D85% of your app's HTML templates were rendered during tests.
Attempts:
2 left
💡 Hint

Think about what coverage tools measure: code execution, not test success or database queries.

📝 Syntax
intermediate
2:00remaining
Correct command to run Django tests with coverage
Which command correctly runs Django tests with coverage and generates an HTML report?
Acoverage run manage.py test && coverage html
Bpython coverage run test manage.py && coverage html
Ccoverage test manage.py && coverage html
Dpython manage.py coverage test && coverage report
Attempts:
2 left
💡 Hint

Remember the order: coverage run runs a command, then coverage html generates the report.

🔧 Debug
advanced
2:00remaining
Why does coverage report show 0% after running Django tests?
You ran coverage run manage.py test but the coverage report shows 0% coverage. What is the most likely cause?
AYour tests passed too quickly for coverage to record data.
BYour tests did not import any code from your app.
CYou forgot to install the coverage package.
DYou ran tests without the coverage tool actually monitoring the code execution.
Attempts:
2 left
💡 Hint

Think about how coverage tracks code execution and what happens if it is not properly started.

state_output
advanced
2:00remaining
Interpreting coverage report details
After running coverage on your Django app, the report shows:
Name                  Stmts   Miss  Cover
-----------------------------------------
myapp/views.py           50     10    80%
myapp/models.py          30      0   100%
myapp/forms.py           20      5    75%

How many lines of code were missed in total?
A15 lines missed
B5 lines missed
C10 lines missed
D0 lines missed
Attempts:
2 left
💡 Hint

Add the missed lines from each file.

🧠 Conceptual
expert
2:00remaining
Why exclude migrations from coverage reports in Django?
Why is it common to exclude migration files from coverage reports in Django projects?
ABecause migrations are always 100% covered by default.
BBecause migration files are auto-generated and not part of the app's logic to test.
CBecause migrations run only in production, not during tests.
DBecause coverage tools cannot read migration files.
Attempts:
2 left
💡 Hint

Think about what migrations are and why testing them is usually unnecessary.