# Python testing libraries

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

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [pytest](#pytest) | 977.1M | 14.7K | Oct 2026 | MIT |
| [Hypothesis](#hypothesis) | 71.6M | 9.2K | Nov 2026 | MPL-2.0 |
| [parameterized](#parameterized) | 14.5M | 859 | Mar 2023 | FreeBSD |
| [behave](#behave) | 4.0M | 3.5K | Sep 2025 | BSD-2-Clause |
| [Robot Framework](#robot-framework) | 3.6M | 12.0K | Nov 2026 | Apache-2.0 |
| [PyHamcrest](#pyhamcrest) | 2.6M | 809 | Oct 2023 | BSD-3-Clause |
| [testfixtures](#testfixtures) | 2.1M | 244 | Oct 2026 | MIT |
| [ddt](#ddt) | 1.3M | 444 | Feb 2024 | MIT |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[pytest](#pytest) has the most monthly downloads in this comparison, at 977.1M.

## Capabilities

| Library | Declared input cases | Property-based generation |
| --- | --- | --- |
| [pytest](#pytest) | Yes | Via plugin |
| [Hypothesis](#hypothesis) | Yes | Yes |
| [parameterized](#parameterized) | Yes | No |
| [behave](#behave) | Yes | No |
| [Robot Framework](#robot-framework) | Yes | No |
| [PyHamcrest](#pyhamcrest) | No | No |
| [testfixtures](#testfixtures) | No | No |
| [ddt](#ddt) | Yes | No |

## Libraries

### pytest

[GitHub](https://github.com/pytest-dev/pytest) · [PyPI](https://pypi.org/project/pytest) · [Docs](https://docs.pytest.org/en/stable/)

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
- Capabilities: [From the pytest docs](https://docs.pytest.org/en/stable/)

**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.

**Watch out for**

- **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.

```sh
pip install -U pytest
```

**pytest-dev/pytest-mock** (2.0K stars)

[pytest-dev/pytest-mock](https://github.com/pytest-dev/pytest-mock) 

```python
def pytest_addoption(parser: Any) -> None:
    parser.addini(
        "mock_traceback_monkeypatch",
        "Monkeypatch the mock library to improve reporting of the "
        "assert_called_... methods",
        default=True,
    )
    parser.addini(
        "mock_use_standalone_module",
        'Use standalone "mock" (from PyPI) instead of builtin "unittest.mock" '
        "on Python 3",
        default=False,
    )

```

[src/pytest_mock/plugin.py](https://github.com/pytest-dev/pytest-mock/blob/78e4a642a74b27f02b90b10a67a98c2f50f50b5e/src/pytest_mock/plugin.py#L762-L774) · [More projects using pytest →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20pytest%20for%20plugin%20configuration%2C%20generated%20API%20request%20cases%20and%20test%20listener%20lifecycle%20handling&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import pytest

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

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

```

From [getting-started.html](https://docs.pytest.org/en/stable/getting-started.html)

### Hypothesis

[GitHub](https://github.com/HypothesisWorks/hypothesis) · [PyPI](https://pypi.org/project/hypothesis) · [Docs](https://hypothesis.readthedocs.io/)

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
- Capabilities: [From the Hypothesis docs](https://hypothesis.readthedocs.io/)

**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.

**Watch out for**

- **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.

```sh
pip install hypothesis
```

**schemathesis/schemathesis** (3.8K stars)

[schemathesis/schemathesis](https://github.com/schemathesis/schemathesis) 

```python
def _draw_body_media_type(draw: st.DrawFn, operation: APIOperation, parameter: OpenApiBody) -> str:
    # Parameter may have a wildcard media type. In this case, choose any supported one
    try:
        possible_media_types = sorted(
            operation.schema.transport.get_matching_media_types(parameter.media_type), key=lambda x: x[0]
        )
    except MalformedMediaType as exc:
        raise InvalidSchema.from_malformed_media_type(
            exc, parameter.media_type, path=operation.path, method=operation.method
        ) from exc
    if not possible_media_types:
        all_media_types = operation.schema.get_request_payload_content_types(operation)
        if all(
            operation.schema.transport.get_first_matching_media_type(media_type) is None
            for media_type in all_media_types
        ):
            # No media type of this operation is supported
            raise SerializationNotPossible.from_media_types(*all_media_types) from None
        # Other media types are possible - avoid choosing this media type in the future
        event_text = f"Can't serialize data to `{parameter.media_type}`."
        note(f"{event_text} {SERIALIZERS_SUGGESTION_MESSAGE}")
        event(event_text)
        reject()
    media_type, _ = draw(st.sampled_from(possible_media_types))
    return media_type

```

[src/schemathesis/specs/openapi/_hypothesis.py](https://github.com/schemathesis/schemathesis/blob/d44b74cc66bf1ae760c7238060ffc31e51dcfe51/src/schemathesis/specs/openapi/_hypothesis.py#L353-L377) · [More projects using Hypothesis →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20hypothesis%20for%20plugin%20configuration%2C%20generated%20API%20request%20cases%20and%20test%20listener%20lifecycle%20handling&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
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()

```

From [quickstart.html](https://hypothesis.readthedocs.io/en/latest/quickstart.html)

### parameterized

[GitHub](https://github.com/wolever/parameterized) · [PyPI](https://pypi.org/project/parameterized)

Parameterizes tests in any Python test framework.

- Downloads / mo: 14.5M
- Stars: 859
- Last release: 0.9.0
- License: FreeBSD
- Capabilities: [From the parameterized docs](https://github.com/wolever/parameterized)

```sh
pip install parameterized
```

**Quickstart**

```python
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()

```

From [README.rst](https://github.com/wolever/parameterized/blob/master/README.rst) · [Find projects using parameterized →](https://dashboard.exa.ai/playground/search?q=parameterized%20GitHub%20projects)

### behave

[GitHub](https://github.com/behave/behave) · [PyPI](https://pypi.org/project/behave) · [Docs](https://behave.readthedocs.io/)

Runs behavior-driven development tests in Python.

- Downloads / mo: 4.0M
- Stars: 3.5K
- Last release: 1.3.3
- License: BSD-2-Clause
- Capabilities: [From the behave docs](https://behave.readthedocs.io/)

```sh
pip install behave
```

**Quickstart**

```python
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

```

From [tutorial.rst](https://behave.readthedocs.io/en/latest/tutorial/) · [Find projects using behave →](https://dashboard.exa.ai/playground/search?q=behave%20GitHub%20projects)

### Robot Framework

[GitHub](https://github.com/robotframework/robotframework) · [PyPI](https://pypi.org/project/robotframework) · [Docs](https://robotframework.org/)

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
- Capabilities: [From the Robot Framework docs](https://robotframework.org/)

**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.

**Watch out for**

- **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.

```sh
pip install robotframework
```

**robocorp/rpaframework** (1.6K stars)

[robocorp/rpaframework](https://github.com/robocorp/rpaframework) 

```python
def end_keyword(self, name, attributes):  # pylint: disable=W0613
    """Listener method for keyword end.

    :param name: keyword name
    :param attributes: keyword attributes

    If `name` exists in the protected keywords list then log level is
    restored back to level it was before settings to NONE.
    """
    if not self._is_robot_running():
        return

    normalized = self._normalize(name)

    if self.stack and self.stack[-1][0] == normalized:
        _, old = self.stack.pop()
        BuiltIn().set_log_level(old)

    # Run-on-failure

    if normalized != self.muted_keyword:
        return

    self.logger.debug("Un-muting failures after keyword: %s", name)
    for library, _ in self.muted_optionals:
        previous = self.muted_previous.get(library.__class__.__name__)
        if previous:
            library.register_keyword_to_run_on_failure(previous)

    self.muted_keyword = None
    self.muted_previous = {}

```

[packages/core/src/RPA/core/logger.py](https://github.com/robocorp/rpaframework/blob/28d63f055bd60afbd8b65d6d0471835d577c40a2/packages/core/src/RPA/core/logger.py#L266-L296) · [More projects using Robot Framework →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20robotframework%20for%20plugin%20configuration%2C%20generated%20API%20request%20cases%20and%20test%20listener%20lifecycle%20handling&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
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()

```

From [robot.running.html](https://robot-framework.readthedocs.io/en/stable/autodoc/robot.running.html)

### PyHamcrest

[GitHub](https://github.com/hamcrest/PyHamcrest) · [PyPI](https://pypi.org/project/PyHamcrest) · [Docs](https://pyhamcrest.readthedocs.io/)

Provides Hamcrest matcher objects.

- Downloads / mo: 2.6M
- Stars: 809
- Last release: 2.1.0
- License: BSD-3-Clause
- Capabilities: [From the PyHamcrest docs](https://pyhamcrest.readthedocs.io/)

```sh
pip install PyHamcrest
```

**Quickstart**

```python
from hamcrest import assert_that, equal_to

assert_that(1 + 1, equal_to(2))

```

From [tutorial.rst](https://pyhamcrest.readthedocs.io/en/latest/tutorial.html) · [Find projects using PyHamcrest →](https://dashboard.exa.ai/playground/search?q=PyHamcrest%20GitHub%20projects)

### testfixtures

[GitHub](https://github.com/simplistix/testfixtures) · [PyPI](https://pypi.org/project/testfixtures) · [Docs](https://testfixtures.readthedocs.io/)

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

- Downloads / mo: 2.1M
- Stars: 244
- Last release: 12.4.0
- License: MIT
- Capabilities: [From the testfixtures docs](https://testfixtures.readthedocs.io/)

```sh
pip install testfixtures
```

**Quickstart**

```python
from testfixtures import compare

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

```

From [comparing.rst](https://github.com/simplistix/testfixtures/blob/main/docs/comparing.rst) · [Find projects using testfixtures →](https://dashboard.exa.ai/playground/search?q=testfixtures%20GitHub%20projects)

### ddt

[GitHub](https://github.com/datadriventests/ddt) · [PyPI](https://pypi.org/project/ddt) · [Docs](https://ddt.readthedocs.io/)

Generates data-driven tests.

- Downloads / mo: 1.3M
- Stars: 444
- Last release: 1.7.2
- License: MIT
- Capabilities: [From the ddt docs](https://ddt.readthedocs.io/)

```sh
pip install ddt
```

**Quickstart**

```python
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()

```

From [test_example.py](https://github.com/datadriventests/ddt/blob/eae90056afa216255e824e503e9511ba3037a60b/test/test_example.py) · [Find projects using ddt →](https://dashboard.exa.ai/playground/search?q=ddt%20GitHub%20projects)

## FAQ

### Which Python testing framework should I use?

[pytest](#pytest) suits most projects, with composable fixtures and parameterized cases. [Hypothesis](#hypothesis) adds generated inputs and shrinks failing cases. [Robot Framework](#robot-framework) and [behave](#behave) suit keyword-driven and behavior-driven acceptance tests.

### What is Robot Framework?

[Robot Framework](#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.

### pytest vs unittest: which should I use?

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

### How do I run Python tests in parallel?

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

### What is Hypothesis?

[Hypothesis](#hypothesis) generates test inputs from strategies and reduces failing cases to simpler examples. Its tests run through pytest.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python testing libraries pytest unittest Hypothesis Robot Framework code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
