Python testing libraries

Updated Nov 2026

Python testing libraries run automated checks against code, from a single function to a full acceptance scenario. A test runner discovers test functions or scenarios, runs them, and reports each failed assertion. These libraries let developers catch regressions before code reaches production.

Popularity

pytest has the most monthly downloads in this comparison, at 977.1M.

LibraryMonthly downloadsStarsLast releaseLicense
pytest
977.1M
14.7KOct 2026MIT
Hypothesis
71.6M
9.2KNov 2026MPL-2.0
parameterized
14.5M
859Mar 2023FreeBSD
behave
4.0M
3.5KSep 2025BSD-2-Clause
Robot Framework
3.6M
12.0KNov 2026Apache-2.0
PyHamcrest
2.6M
809Oct 2023BSD-3-Clause
testfixtures
2.1M
244Oct 2026MIT
ddt
1.3M
444Feb 2024MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Runs Python tests with assertions, reusable fixtures, parameterized cases, and plugins.

Downloads / mo
977.1M
Stars
14.7K
Last release
9.2.0
License
MIT

Strengths

  • Composes reusable test fixtures. Share setup and cleanup through fixtures with explicit dependency relationships.
  • Generates predefined test cases. Run the same test function against declared argument combinations.

Limitations

  • Parallel execution needs a plugin. Use pytest-xdist to distribute tests across worker processes.
  • Parameter values are passed unchanged. Copy mutable inputs when one parameterized case modifies them.

Quickstart

From getting-started.html
$ pip install -U pytest
import pytest

def test_addition():
    assert 1 + 1 == 2

if __name__ == "__main__":
    raise SystemExit(pytest.main([__file__, "-q"]))

pytest examples

From open-source projects on GitHub

Generates test inputs from strategies and reduces failing cases to simpler examples.

Downloads / mo
71.6M
Stars
9.2K
Last release
6.170.15
License
MPL-2.0

Strengths

  • Generates constrained test inputs. Describe valid input data with composable strategies instead of enumerating every example.
  • Shrinks failing generated cases. Reduce a generated failure to a smaller example that still fails.

Limitations

  • Fixtures persist across generated examples. Reset mutable fixture state inside each generated example.
  • Excessive filtering triggers health checks. Build valid data directly when filtering rejects too many examples.

Quickstart

From quickstart.html
$ pip install hypothesis
from hypothesis import given, strategies as st

@given(st.lists(st.integers()))
def test_sorted_length(values):
    assert len(sorted(values)) == len(values)

test_sorted_length()

Hypothesis examples

From open-source projects on GitHub

parameterized

Parameterizes tests in any Python test framework.

Downloads / mo
14.5M
Stars
859
Last release
0.9.0
License
FreeBSD

Quickstart

From README.rst
$ pip install parameterized
import unittest
from parameterized import parameterized

class AdditionTests(unittest.TestCase):
    @parameterized.expand([(1, 2, 3), (2, 3, 5)])
    def test_addition(self, left, right, expected):
        self.assertEqual(left + right, expected)

if __name__ == "__main__":
    unittest.main()

Runs behavior-driven development tests in Python.

Downloads / mo
4.0M
Stars
3.5K
Last release
1.3.3
License
BSD-2-Clause

Quickstart

From tutorial.rst
$ pip install behave
mkdir -p features/steps
cat > features/example.feature <<'EOF'
Feature: Arithmetic
  Scenario: Add two numbers
    Given two numbers are added
EOF
cat > features/steps/example.py <<'EOF'
from behave import given

@given("two numbers are added")
def step_add(context):
    assert 1 + 1 == 2
EOF
behave

Robot Framework

Runs keyword-driven acceptance tests and automation tasks with extensible Python libraries.

Downloads / mo
3.6M
Stars
12.0K
Last release
7.5.1
License
Apache-2.0

Strengths

  • Extends through Python test libraries. Expose Python functions as reusable test keywords.
  • Creates machine-readable execution results. Write execution results as XML or JSON for downstream tools.

Limitations

  • Parallel execution needs another runner. Use Pabot to split suites across separate processes.
  • Global libraries share mutable state. Reset state explicitly when a GLOBAL library is reused across tests.

Quickstart

From robot.running.html
$ pip install robotframework
from robot.api import TestSuite

suite = TestSuite("Example")
test = suite.tests.create("Values match")
test.body.create_keyword("Should Be Equal", args=["hello", "hello"])
result = suite.run()

Robot Framework examples

From open-source projects on GitHub

PyHamcrest

Provides Hamcrest matcher objects.

Downloads / mo
2.6M
Stars
809
Last release
2.1.0
License
BSD-3-Clause

Quickstart

From tutorial.rst
$ pip install PyHamcrest
from hamcrest import assert_that, equal_to

assert_that(1 + 1, equal_to(2))

testfixtures

Provides helpers and mock objects for unit tests and doc tests.

Downloads / mo
2.1M
Stars
244
Last release
12.4.0
License
MIT

Quickstart

From comparing.rst
$ pip install testfixtures
from testfixtures import compare

compare({"answer": 42}, {"answer": 42})

Generates data-driven tests.

Downloads / mo
1.3M
Stars
444
Last release
1.7.2
License
MIT

Quickstart

From test_example.py
$ pip install ddt
import unittest
from ddt import ddt, data

@ddt
class PositiveTests(unittest.TestCase):
    @data(1, 2, 3)
    def test_positive(self, value):
        self.assertGreater(value, 0)

if __name__ == "__main__":
    unittest.main()

FAQ

pytest suits most projects, with composable fixtures and parameterized cases. Hypothesis adds generated inputs and shrinks failing cases. Robot Framework and behave suit keyword-driven and behavior-driven acceptance tests.

Robot Framework runs keyword-driven acceptance tests and automation tasks, with Python libraries exposed as reusable keywords. It stores execution results in XML or JSON.

unittest provides class-based test cases and fixture lifecycles. pytest provides composable fixtures and declared argument combinations. Its fixtures cannot pass directly into unittest TestCase methods.

The pytest-xdist plugin distributes pytest test execution across workers. Pabot runs Robot Framework suites in separate processes.

Hypothesis generates test inputs from strategies and reduces failing cases to simpler examples. Its tests run through pytest.

For coding agents

Found your testing library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official