commaai / openpilot

openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for 250+ supported car makes and models.
https://comma.ai/
MIT License
48.72k stars 8.84k forks source link

Improve pytest collection time to <2s #32611

Open sshane opened 1 month ago

sshane commented 1 month ago

Currently it takes ~6-7s with these plugins:

platform linux -- Python 3.11.4, pytest-8.2.1, pluggy-1.5.0
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Using --randomly-seed=3123610973
rootdir: /home/batman/openpilot
configfile: pyproject.toml
testpaths: tools/, common/, system/, selfdrive/
plugins: anyio-4.3.0, timeout-2.3.1, xdist-3.6.1, cpp-2.5.0, cov-5.0.0, mock-3.14.0, forked-1.6.0, dash-2.11.1, benchmark-4.0.0, randomly-3.15.0, subtests-0.12.1, flaky-3.8.1, hypothesis-6.47.5, asyncio-0.23.7, nbmake-1.5.3, repeat-0.9.3
asyncio: mode=Mode.STRICT

============================================================================= 4011 tests collected in 6.46s ==============================================================================

real    0m8.935s
user    0m10.833s
sys     0m2.163s

Verification:

Run time pytest --collect-only in the root openpilot directory and post both the real time and the collection time as reported by pytest (=== 4011 tests collected in 6.61s ===). Include the times before and after your PR.

BBBmau commented 1 month ago

should the time improvement come from not making changes to the testpath?

You can easily improve by being explicit in testpaths. Doesn't seem like that's the point of this bounty if it's that easy.

sshane commented 1 month ago

pytest selfdrive/car/tests --co takes 1.5s on its own.

renxida commented 1 week ago

============ 4172 tests collected in 2.05s ============

running pytest --co today gives the above output.

Perhaps it's time to close this and give the bounty to whoever got this here.

(just tried again. when i delete the cache, it takes 3.76s)