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 Playground

Tags

packagetestingframeworkfixtureparametrize

Related Items