Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

pytest

Automatic checks for your Python code.

TestingPYPI

GitHubWebsite

1. License

“Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction”

MIT allows use in paid and closed products; pytest usually stays a development tool and is not shipped.

github.com/pytest-dev/pytest/blob/main/LICENSE

From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error

What pytest does

pytest is a free tool that runs small checks, called tests, on your Python code and tells you which ones fail and why. Your AI assistant writes the tests next to the code, and one command shows if a change broke something. It works for a single script as well as a large app.

What people build with it

Check prices before each release

Your shop or booking app works out totals and discounts; one test table runs every coupon case, and a wrong number stops the release.

Test file exports without mess

Code that writes receipts, reports or uploads gets a fresh empty folder for each test, so no test leaves files in your project.

Test settings without real services

Point the app at a local address or a fake payment service for one test only; pytest puts the real setting back afterwards.

Check that bad input is refused

Make sure a sign-up form or an import rejects wrong data with a clear error instead of saving it.

Run old unittest suites as they are

An older project with tests in the built-in unittest style can switch to pytest without rewriting them first.

Let the assistant check its own edits Idea

After each change your AI assistant runs the tests and reads the failure report, which shows the values that did not match, before it says the work is done.

pytest popularity

81 / 100
Gid Score, #85 overall
239M
downloads a week, pypi
14.7K
GitHub stars
257
agent projects use it
pytest: downloads per weekPyPI, pytest 239,198,733
pytest: GitHub starspytest-dev/pytest 14,742

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How pytest is used

  • pytest is a dependency in 257 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (15.8% of the 1,623 Python ones), #6 of 122 in testing.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,766; those are left out of every share on this page.
  • Projects that use it most often also use python-dotenv (55.6%), Pydantic (51.4%), Uvicorn (49.8%).
  • It is more common in projects set up for Roo Code (10.8%) than for Gemini CLI (2.7%).

By coding agent

134 projects, 4.1%
133 projects, 4.4%
94 projects, 3.8%
17 projects, 5.1%
16 projects, 5.7%
14 projects, 3.0%
13 projects, 2.7%
12 projects, 10.8%

Often used with

In 55.6% of its projects
In 51.4% of its projects
In 49.8% of its projects
In 46.7% of its projects
In 42.8% of its projects
In 40.5% of its projects
In 37.0% of its projects
In 33.1% of its projects

More about pytest

Funding
  • GitHub Sponsors: https://github.com/pytest-dev
  • Tidelift: https://tidelift.com/funding/github/pypi/pytest
  • Open Collective: https://opencollective.com/pytest
  • thanks.dev: https://thanks.dev/u/gh/pytest-dev
  • Own page: https://docs.pytest.org/en/stable/sponsor.html
  • 17 GitHub sponsors

See all

More in Testing

Alternatives

pytest This page

MITGid 81239M/wk

Vitest

Pick Vitest when the code to test is JavaScript or TypeScript in a Vite project, not Python.

Nose

Nose is an older Python test runner built on unittest; pick it only to keep an old suite running as it is.

Compare pytest with another tool

Get started

Tell your AI assistant

“Add pytest (pin pytest==9.2.0, Python 3.10+) as a dev dependency, write tests in tests/test_*.py for the main functions with fixtures, parametrize and tmp_path, run python -m pytest -q and fix the code until every test passes.”

  1. Install pytest into your project's virtual environment, not into the system Python.

    python3 -m venv .venv
    source .venv/bin/activate   # on Windows: .venv\Scripts\activate
    pip install -U pytest
    

    From docs.pytest.org/en/stable/getting-started.html

  2. Write a file whose name starts with test_ and put plain assert lines in functions whose names start with test_.

    # content of test_sample.py
    def func(x):
        return x + 1
    
    
    def test_answer():
        assert func(3) == 5
    

    From docs.pytest.org/en/stable/getting-started.html

  3. Run pytest in the project folder; it finds the test files and prints a report for each failure.

    $ pytest

    From docs.pytest.org/en/stable/getting-started.html

Mistakes to avoid

async def test_fetch(): ... with plain pytest
Install an async plugin (pytest-asyncio or anyio) and mark the test as that plugin's docs say

In our run with pytest 9.2.0 the test failed with "async def functions are not natively supported" and a list of plugins.

@pytest.mark.parametrize("a", [1, 2], True, ["one", "two"]) # indirect and ids passed by position
@pytest.mark.parametrize("a", [1, 2], indirect=True, ids=["one", "two"])

Since pytest 9.2.0 indirect, ids and scope are keyword-only and positional use raises a TypeError.

Tests in tests/ fail with ModuleNotFoundError for the app's own module when the code lives in src/
Install the project in editable mode, or set pythonpath = ["src"] in the pytest config

Without an editable install pytest does not see the src folder; our demo used pythonpath = ["."] for a flat folder.

Adding [tool.pytest] to pyproject.toml while [tool.pytest.ini_options] is still there
Keep one of the two tables; the native [tool.pytest] table needs pytest 9.0 or newer

pytest 9.0 added the native TOML table but does not accept both tables at once.

A test class named CheckCart or a file named cart_tests.py
Name files test_*.py or *_test.py and classes Test*, with test_* functions inside

Other names are not collected, so the tests silently never run.

Questions

Do I need special check functions like assertEqual?

No. You write plain Python assert lines, and pytest shows the values on both sides when one fails.

Can I use it in a commercial project?

Yes. It is under the MIT license, which allows commercial use.

How do tests get shared setup like a sample cart or a database?

Through fixtures. A test names a fixture as an argument and pytest passes in what the fixture returns.

Will my old unittest tests run?

Yes. pytest runs unittest suites without changes.

Is it still maintained?

Yes. Version 9.2.0 came out on 27 October 2026.