pytest-collect-profile
Find what makes pytest collection slow.
pytest-collect-profile shows which collector operations take the most time and how long collection takes overall. It measures pytest directly, including custom collectors, so the report matches the suite pytest actually sees.
Installation
python -m pip install pytest-collect-profile
Quick start
Profile collection only — recommended
pytest --collect-profile-only
Start here when you want a diagnosis, not a test run. Pytest collects and selects the tests, the plugin prints one report, and the run stops. It does not print the usual list of collected nodes.
Only the 10 slowest collector operations are shown. The output stays useful in a terminal, a CI log, or coding-agent context even for large suites.
Profile collection, then run tests
pytest --collect-profile
Use this when you want to see the profile without changing your normal test run. The selected tests execute after the report is printed.
Need pytest's complete collected-node listing? Add --collect-only or --co to either command. An explicit pytest collect-only option keeps its native output.
Example report
====================== collect profile ======================
time collector node
1.421s Module tests/integration/test_api.py
0.612s Class tests/test_users.py::TestUsers
0.184s Directory tests/integration
Total collection: 2.340s | 842 items
Reading the report
- The slowest collector operations appear first, with at most 10 rows.
Total collectionmeasures the complete collection phase separately.- Collector calls may be nested, so row times can overlap and are not meant to add up to the total.
- An empty root-session node ID is shown as
<session>.
The report points to where collection time is spent. It does not guess why a collector is slow or promise that changing one row will reduce the total by the same amount.
Works with pytest
- The plugin is silent unless one of its two profiling options is present.
- Pytest continues to own selection, diagnostics, warnings, and exit status.
-q,-qq, and-vkeep their normal pytest meaning.- Timings exist only for the current process. The plugin stores no history or cache and makes no network requests.
Compatibility
pytest-collect-profile requires Python 3.10 or newer and pytest 8.0 or newer. The project targets Linux, macOS, and Windows, with CI coverage across Python 3.10 through 3.14 and representative pytest 8.x and 9.x releases.
pytest-xdist
For a meaningful collection profile, run xdist projects serially:
pytest -n0 --collect-profile-only
The profile-only mode rejects active distributed execution and points to -n0. The regular --collect-profile mode does not aggregate worker results, so -n0 is recommended there as well.
Focused by design
pytest-collect-profile does one thing: profile collection. It does not profile test execution, fixtures, functions, or call stacks. It does not provide exports, history, run-to-run comparisons, thresholds, or configurable rankings and filters.
See the contribution guide for contribution guidance. This project is available under the terms of the MIT License.
Release files for pytest-collect-profile 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_collect_profile-0.2.0.tar.gz | 12.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_collect_profile-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / pytest_collect_profile-0.2.0.tar.gz
| Download URL | pytest_collect_profile-0.2.0.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7430c342b9c380b75cd8d511bd8ad8238431fa199affcb34712e52e2ba5c074e
|
|
BLAKE2b-256 checksum How to use checksums |
5975690bea426f25bd9e24691626f7f762a18bfcc81687cef038059ab43a77e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logRelease files / pytest_collect_profile-0.2.0-py3-none-any.whl
| Download URL | pytest_collect_profile-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1b1e18209b4a7444261718d6842f051500b2c4ef4929e32f56f80e713826172
|
|
BLAKE2b-256 checksum How to use checksums |
37b2b3079cd1ef6fc8d11141dd11303abfc10343f675865fda8c38eac51346c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency log