Skip to main content

PyTest

PyTest is the most widely used testing framework for Python, known for its concise syntax (plain `assert` statements instead of special assertion methods), powerful fixture system for setup and teardown, and a large plugin ecosystem. It's the default choice for most Python test automation.

Where older Python testing frameworks required subclassing a TestCase class and calling assertion methods, PyTest lets a test be a plain function using Python's built-in `assert` keyword, with PyTest introspecting the failure to produce a detailed, readable error message automatically.

Its fixture system is a particular strength for data-driven and parameterized testing — fixtures can be scoped (per-test, per-module, per-session), composed together, and reused across many test files, making it straightforward to set up shared test data or environment state cleanly.

Example

def add(a, b):
    return a + b

def test_add_sums_two_numbers():
    assert add(2, 3) == 5

A PyTest test — a plain function with a plain assert.

PyTest — Definition, Example & How It's Used | QA Bash Glossary | QA Bash