Bird
0
0

Identify the error in this unittest test case that will cause it to fail to run:

medium📝 Debug Q14 of 15
PyTest - Basics and Setup
Identify the error in this unittest test case that will cause it to fail to run:
import unittest

class TestMath(unittest.TestCase):
    def test_add(self):
        assert 1 + 1 == 2
AMissing self.assertEqual method for assertion
BClass name should not start with Test
CMissing import for pytest
DFunction name should not start with test
Step-by-Step Solution
Solution:
  1. Step 1: Check unittest assertion style

    unittest requires using self.assertEqual or other assert methods, not bare assert statements.
  2. Step 2: Identify error cause

    Using bare assert inside unittest.TestCase method will not be recognized properly and may cause test to be ignored or fail.
  3. Final Answer:

    Missing self.assertEqual method for assertion -> Option A
  4. Quick Check:

    unittest needs self.assertEqual, not bare assert [OK]
Quick Trick: Use self.assertEqual in unittest, not bare assert [OK]
Common Mistakes:
MISTAKES
  • Using bare assert in unittest tests
  • Thinking pytest syntax works in unittest
  • Ignoring class and method naming conventions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes