Bird
0
0

You wrote this Django test but it fails with an error:

medium📝 Debug Q14 of 15
Django - Testing Django Applications
You wrote this Django test but it fails with an error:
from django.test import TestCase

class MyTest(TestCase):
    def test_example(self):
    self.assertTrue(True)

What is the problem?
AIndentation error in the test method
BMissing import for assertTrue
CTestCase class is not imported
DassertTrue is not a valid method
Step-by-Step Solution
Solution:
  1. Step 1: Check the test method indentation

    The line self.assertTrue(True) is not indented inside the method properly.
  2. Step 2: Understand Python indentation rules

    Python requires code inside functions to be indented; missing indentation causes an error.
  3. Final Answer:

    Indentation error in the test method -> Option A
  4. Quick Check:

    Indent code inside methods [OK]
Quick Trick: Indent test code inside methods correctly [OK]
Common Mistakes:
MISTAKES
  • Forgetting to indent inside functions
  • Assuming assertTrue needs import
  • Thinking TestCase import is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes