pytest's mechanics: rewritten asserts, bare invocation, and a dependency floor that rules out older Python
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
At a glance
- What is it?
- pytest is the MIT licensed Python test framework whose whole first run is one command, but its real constraints sit in pyproject.toml: a Python 3.10 floor, a pluggy ceiling below 2, a version number taken from git tags, and no mocking library in the core.
- Who is it for?
- pytest fits Python 3.10 and newer projects that want plain assert statements, auto-discovery, and fixtures without a class based test base. It does not fit codebases pinned to Python 3.9 or older, plugins built against pluggy 2, or teams who expect mocking to arrive with the framework.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 1 day ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 14, 2026, and from our analysis. They are not legal advice.
Star history
- pytest-dev/pytest14,685 ★ · +165
| Repository | 2026-09-21 | 2026-11-14 |
|---|---|---|
| pytest-dev/pytest | 14.5k | 14.7k |
165 Stars in the last 54 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
A bare pytest run rewrites the assert and prints the operand that broke it
The smallest useful pytest file is this one:
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5Run it with no arguments at all, `pytest`, and the report names the file, the test, and the line, test_sample.py:5, then prints the comparison operands, `assert 4 == 5`, and a note showing where the 4 came from with `+ where 4 = inc(3)`. That expansion is the assertion introspection the project sells: you write a Python assert and pytest supplies the intermediate value, so nobody has to remember a family of self.assert method names. The consequence is that the useful part of a failing test report is generated by pytest rather than by Python itself. A failure message that quotes operands is pytest output, and a project that wants that level of detail in its logs gets it by running under this runner, not by rewriting its asserts by hand.
Discovery runs with zero configuration, and the repository carries no ini example
The invocation in the project README is a bare `pytest`, with no path, no test name, and no configuration flag, which only works because test modules and functions are auto-discovered. The collected count appears on the second line of the report, `collected 1 items`, so you can see discovery working rather than having to infer it. What the README does not contain is any ini file example: there is a pyproject.toml, a tox.ini, and a MANIFEST.in at the root, yet the README prints no configuration block and no marker expression. The consequences for a reader are practical. If your existing layout does not match the default discovery rules, nothing is collected and the run looks like a suite with no tests in it, and the fix is not shown in the README. The naming and pattern rules live in the hosted documentation at docs.pytest.org, so onboarding a new repository means going off the checkout to learn how collection decides what to run.
Fixtures cover long-lived resources, and the README shows none of the syntax
Fixtures are named in the feature list as modular fixtures for managing small or parametrized long-lived test resources, which is the framework's answer to setup and teardown that runs once per scope rather than once per test. The word parametrized is doing work there: the same mechanism covers a table driven value set and an expensive shared resource. The top-level file, however, contains no fixture definition, no scope argument, and no conftest example, so the feature is advertised without a single line of its API. For a reader migrating from unittest, that matters, because unittest's setUp, tearDown, setUpClass, and tearDownClass have no direct spelling here in the documentation you are given at a glance. The repository does carry a doc/ directory and points at docs.pytest.org/en/stable/explanation/fixtures.html for the real reference, which means the mental model for shared state has to be learned before the first fixture is written, not while debugging one.
unittest suites run under it unchanged, which cuts both ways
One of the six feature bullets states that pytest can run unittest, or trial, test suites out of the box, and the project keywords in pyproject.toml list unittest alongside test. That is the adoption story: a large existing suite can be pointed at this runner before a single test is rewritten, and plain unittest TestCase classes, setUp methods, and assertEqual calls keep working unchanged. The consequence cuts the other way too. Migration is therefore incremental but uneven: the older a test is, the less the runner adds to it, and a suite can sit unchanged for years without anyone noticing which parts would report better once converted.
Two interpreters get two different dependency sets below Python 3.11
The packaging metadata is where the real constraints live. `requires-python` is set to `>=3.10`, the classifiers stop at Python 3.15, and one of them reads `Programming Language :: Python :: 3 :: Only`. The runtime dependencies are seven entries, and two of them are conditional on the interpreter: `exceptiongroup>=1; python_version<'3.11'` and `tomli>=2; python_version<'3.11'`, which backport standard-library features that later interpreters provide. `colorama>=0.4` is pinned to `sys_platform=='win32'`, so Windows installs carry an extra package that Linux ones never see. The consequence for readers is that two machines in the same project can hold visibly different sets of installed packages, and any attempt to explain a missing module starts with that split. A project still supporting Python 3.9 cannot install current pytest at all, so upgrading the runner and upgrading the interpreter have to be scheduled together.
The plugin ceiling is pluggy's, and 1300 plugins all live under it
The feature list advertises a rich plugin architecture with over 1300 external plugins, and the mechanism behind that is a single dependency: `pluggy>=1.6,<2`. The upper bound is the part worth reading twice. It means pytest will not install alongside pluggy 2, and every plugin in that catalogue resolves its hook library into the same narrow window. That coupling is the cost of a large ecosystem: an extension that needs a newer pluggy cannot be installed without breaking the runner, so the practical ceiling on any plugin is set by pytest's own pin rather than by Python. The same dependency list also has no mocking library, which means the mocking support people expect from a test framework is a plugin decision rather than something these seven packages provide.
The version number is read from git tags, so tarball builds report something else
`pyproject.toml` marks the version as dynamic, and the build backend is setuptools with `setuptools-scm[toml]>=10.1` in its requires list, which is the plugin that derives a version from repository tags. Nothing in the project file states a literal version. The published numbers are the tags instead: 9.2.0 on 2026-10-27, 9.1.1 on 2026-06-19, and 9.1.0 on 2026-06-13, so patch releases arrive as their own tags on the main branch, whose latest push was on 2026-11-02. The consequence is a difference between what you read in the checkout and what you install. A working tree or an archive without tags reports a derived fallback version rather than a release number, so when a bug report mentions the version, the tag list is the thing to match against. The metadata also carries `Development Status :: 6 - Mature` as a classifier, which is a packaging declaration rather than a promise about any single release.
Security problems go to an advisory, not to the issue tracker
The security section is short and specific: if you believe you have found a vulnerability, do not create an issue, and report it through a new security advisory on GitHub instead. The project keeps bugs and feature requests on the public issue tracker, so the two paths are deliberately separate and a mistaken public issue can disclose the problem before a fix exists. The other end of that arrangement falls on users, who have to watch advisories rather than issues to learn about a flaw in the version they run. The repository is organized around the same separation: SECURITY.md and CONTRIBUTING.rst sit at the root, RELEASING.rst describes the tag driven releases, OPENCOLLECTIVE.rst and TIDELIFT.rst cover the two funding routes, and changelog/ plus CHANGELOG.rst hold the history. Licensing is MIT, copyright Holger Krekel and others, 2004, which dates the project far earlier than its current release numbers suggest.
Editorial conclusion
pytest fits Python 3.10 and newer projects that want plain assert statements, auto-discovery, and fixtures without a class based test base. It does not fit codebases pinned to Python 3.9 or older, plugins built against pluggy 2, or teams who expect mocking to arrive with the framework. Before adopting it, read the seven runtime dependencies in pyproject.toml, decide whether your mocking layer is a plugin you will own, and check the changelog page for the version you plan to pin, since the README itself carries no install command or configuration example.
Frequently asked questions
What is a pytest in Python?
It is a Python test framework that makes small tests easy to write and scales to support complex functional testing for applications and libraries. A test is an ordinary function using a plain assert, and running pytest with no arguments collects and runs it.
How do I run a pytest test in Python?
Run `pytest` from the project root with no arguments and no path, as the example in the project README shows. The report lists the collected count, then names the file and line of a failure, such as test_sample.py:5.
how to install pytest
The packaging metadata requires Python 3.10 or newer. Installation instructions are not in the repository README, which sends you to the full documentation including installation at https://docs.pytest.org/en/stable/.
how to use pytest fixtures
Fixtures are listed as modular fixtures for managing small or parametrized long-lived test resources. The README names the feature without showing a fixture definition, and points at docs.pytest.org/en/stable/explanation/fixtures.html for the syntax.
how to use pytest parametrize
The README mentions parametrization only in the fixture feature, where parametrized long-lived test resources are named as one of the things fixtures manage. No parametrize example appears in the repository, so the call syntax has to come from the hosted documentation.
Is pytest difficult to learn?
The entry point is a bare `pytest` command over a file with one function and one assert, and the feature list is six bullets covering assertion output, discovery, fixtures, unittest compatibility, the Python requirement, and plugins. It also runs existing unittest suites without changes.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/pytest-dev-pytest)Star history chart for your README
[](https://hysenlabs.com/projects/pytest-dev-pytest)Was this useful?