pytest
Package — TestingPython 3.8+Intermediate
Feature-rich testing: fixtures, parametrize, plugins, auto-discovery
Quick Info
- Documentation
- Official Docs
- Python Version
- 3.8+
- Dependencies
- iniconfig, packaging, pluggy
- Install
pip install pytest
Learn by Difficulty
Quick Example
python
# Install: pip install pytest # test_example.py import pytest def add(a, b): return a + b def test_add(): assert add(1, 2) == 3 assert add(-1, 1) == 0 def test_add_strings(): assert add("hello", " world") == "hello world" @pytest.fixture def sample_data(): return [1, 2, 3, 4, 5] def test_sum(sample_data): assert sum(sample_data) == 15
pytest is a third-party package. Feature-rich testing: fixtures, parametrize, plugins, auto-discovery. Install with: pip install pytest
Try in PlaygroundTags
packagetestingframeworkfixtureparametrize
Related Items
unittest
Stdlib — Testing
Built-in unit testing framework (TestCase, assertions, runners)
hypothesis
Package — Testing
Property-based testing: auto-generates edge-case test inputs
coverage
Package — Testing
Measure code coverage; shows untested lines/branches
tox
Dev Tool — CI/CD
Test Python packages across multiple environments and versions
nox
Dev Tool — CI/CD
Flexible test automation configured with Python (tox alternative)