How to Test Python Code
Learn what testing means in Python, the core ideas behind automated tests, and the built-in and third-party tools that make testing practical.
Learn Python programming from scratch
Learn what testing means in Python, the core ideas behind automated tests, and the built-in and third-party tools that make testing practical.
Write and run your first Python unit test step by step, using unittest to check a small function and understand the test output.
Learn the core features of Python's built-in unittest framework: assertion methods, setUp and tearDown, test discovery, skipping tests, and subtests.
Learn how pytest simplifies Python testing with plain assert statements, fixtures, parametrize, markers, and built-in unittest compatibility.
Learn how to structure test directories, run tests with unittest and pytest, configure test discovery, and integrate tests into your workflow.
Learn how to test that your Python code raises the right exceptions and handles edge cases like empty inputs, boundary values, and unexpected types.
Learn how to use unittest.mock to replace external dependencies like databases and APIs with mock objects, so your unit tests stay fast and reliable.
Learn how to use coverage.py to measure which lines of your Python code are tested and which are not, so you can identify gaps in your test suite.
See proof that every value in Python is an object: integers, functions, classes, modules, types, and even code itself all share the same object foundation.
Learn the most important special methods in Python: __str__, __repr__, __eq__, __hash__, __bool__, __call__, __getitem__, and more, with practical examples.
Learn to control attribute access on Python objects with __getattr__, __setattr__, __delattr__, and __getattribute__, plus practical customization patterns.
Learn dynamic attribute access with getattr(), setattr(), hasattr(), and delattr(). Build object proxies, attribute delegation, and data-driven attribute patterns.