Running a million empty tests | En kodare

submited by
Style Pass
2024-10-31 08:30:02

Any other tips on how you’re running 2,105 tests in less than 2 minutes? My new project’s suite of 75 tests is already taking 30 seconds.

I thought that surely running a million empty tests would be pretty fast, making a point about it’s “not the amount of tests, but what the tests are doing”. So I created a file with a million empty tests:

That… seemed a bit much to me. Maybe it was just all the printing? -q doesn’t remove the output per test unfortunately, and pytest tests.py -q --assert=plain 2>&1 >/dev/null didn’t change the runtime.

That’s better. I wonder what the absolute minimum theoretical time is? After all, hammett is loading the file, inspecting it to find all functions and executing them all, collecting the results and printing a dot in the terminal for each test.

After asking on the Python Discord ConfusedReptile told me that it’s the bytecode caching that I missed. Deleting __pycache__ and running python -m tests will make it as slow as python tests.py.

Leave a Comment