What is Python's unittest module?
Why Interviewers Ask This
Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.
Answer
Python's built-in unittest module provides a test framework. Tests extend unittest.TestCase and define test methods starting with test_. Setup/teardown: setUp() runs before each test, tearDown() after. Class-level: setUpClass(cls) / tearDownClass(cls). Assertions: assertEqual(a, b), assertNotEqual(), assertTrue(), assertFalse(), assertIsNone(), assertIn(item, container), assertRaises(Exception, callable, *args). Run: python -m unittest discover or python -m unittest test_module. Mocking: from unittest.mock import Mock, patch, MagicMock; @patch("module.ClassName") def test(mock_class): .... Modern alternative: pytest — simpler syntax (plain functions, not classes), more powerful fixtures, rich plugin ecosystem, and better output. Most Python projects prefer pytest.
Common Mistake
Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your Python experience.