Testing
Testing is a critical part of Python development. The standard library provides `unittest`, while third-party `pytest` offers a more concise and powerful alternative. Both are widely used in the Python ecosystem. The guide walks through unittest Basics, Test Fixtures, pytest Fundamentals, pytest Fixtures, Mocking. Subclass `unittest.TestCase` and define methods starting with `test_`. Use assertion methods: `assertEqual(a, b)`, `assertTrue(x)`, `assertRaises(Exc, fn)`. Run with `python -m unittest discover`. Tests are methods, functions are not supported directly. `setUp()` runs before each test method, `tearDown()` runs after. `setUpClass()` / `tearDownClass()` run once per class (use `@classmethod`). `setUpModule()` / `tearDownModule()` run once per module. Fixtures are essential for setting up test data and resources. pytest uses plain functions, not classes. Use plain `assert` statements (no special methods needed). `@pytest.mark.parametrize("input,expected", [(1,2), (3,4)])` runs a test with multiple inputs. Output is verbose and colorful by default. The guide is organized into 5 sections that build on each other, each pairing a prose explanation with runnable code.