Cut the 3 s pytest startup without a warm process

Open
#227 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
34/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

Start by profiling the fast tier with python -X importtime and pytest --collect-only, with xdist off and on, then compare against main and a --testmon run selecting a few tests. Use the results to recommend which startup cost to address first; the issue leaves the implementation choice and whether selection size should control worker count to the maintainer.

Written by the indexing model from the issue text.

Description

Starting four xdist workers and collecting the tests costs 3.1–3.4 s per run, even when no test runs. That is about half the fast tier's wall time. #220 considered a warm test process (pytest-hot-reloading) and turned it down: it is alpha, lists Python only up to 3.12, drops the xdist workers, and can return stale results.

Ways to try, each measured against main on the fast tier and on a --testmon run that selects a few tests:

  1. Profile the startup. Use python -X importtime and pytest --collect-only with xdist off and on, to split the 3 s into interpreter start, plugin loading, imports during collection (torch, matplotlib, jsonschema, sklearn), and worker boot.
  2. Defer heavy imports in test modules. Move module-level imports of torch, matplotlib and the experiment scripts into the tests or fixtures that use them, so that collection imports only what it needs.
  3. Skip xdist for small selections. When --testmon or -k leaves only a few tests, run them in one process, since booting four workers costs more than it saves. pytest-xdist's -n auto does not do this. A pytest_xdist_auto_num_workers hook or a conftest check could.
  4. Disable plugins the fast tier does not use, such as -p no: entries in addopts.

Questions for the maintainer:

  • Which of these to try first? Proposed default: 1, then whichever of 2–4 the profile points to.
  • Is changing worker count by selection size (3) acceptable, given that it makes a run's parallelism depend on how many tests it selects?

Refs #220.

Dominant language
Python
Stars
0
Forks
0
Avg merge
2h 9m
Merged PRs (30d)
164

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from neurodata/prolearn

All issues in neurodata/prolearn

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.