PyTest
The definitive Python testing framework. Powerful fixtures, parameterised tests, and a plugin ecosystem that covers every testing need.
Overview
PyTest is the most popular testing framework for Python. Unlike Python's built-in unittest module, PyTest uses a simple assert statement (no special assertion methods needed) and provides powerful features like fixtures, parameterisation, and plugins. PyTest can run unittest, nose, and doctest-style tests, making it a universal test runner for Python projects.
PyTest's fixture system is particularly powerful — it allows test dependencies (databases, API clients, temporary files) to be injected automatically, with setup and teardown handled declaratively. This makes complex integration tests clean and maintainable.
What it's used for
PyTest is essential for:
- Python unit testing: The standard choice for testing Python code.
- Integration testing: Fixtures make database, API, and service testing elegant.
- API testing: Combined with requests or httpx, PyTest is a powerful API test framework.
- Data-driven testing: Parameterise tests with multiple data sets effortlessly.
Pros & Cons
Pros
- Simple assert syntax — no special assertion methods
- Powerful fixture system for dependency injection
- Excellent parameterisation for data-driven tests
- Massive plugin ecosystem (coverage, HTML reports, parallel execution)
- Can run unittest, nose, and doctest tests
Cons
- Python only — not suitable for other languages
- Fixture hierarchy can become complex in large projects
- Debugging fixture issues requires understanding of scope and resolution
- Some plugins have compatibility issues with newer PyTest versions
- Slower than unittest for very large test suites (though plugins can help)
Platforms & Integrations
PyTest runs on Windows, macOS, and Linux. It requires Python 3.7+. It integrates with all Python build tools and CI platforms.
Pricing
| Tier | Cost | Includes |
|---|---|---|
| Open Source | Free | Full framework, all core features, community support |
NZ Context
PyTest is the standard testing framework in NZ Python teams. Every NZ Python developer job posting lists PyTest as a required or preferred skill. Figured, Vend, and NZ data science teams use PyTest extensively. For NZ testers working with Python backends or data pipelines, PyTest is essential.
Alternatives
- unittest (Python stdlib) — Built-in but less powerful. PyTest can run unittest tests.
- nose2 — Successor to nose. Less popular than PyTest.
- Robot Framework — Keyword-driven testing for teams that want readable tests.