TE
TechEcho
StartseiteTop 24hNeuesteBesteFragenZeigenJobs
GitHubTwitter
Startseite

TechEcho

Eine mit Next.js erstellte Technologie-Nachrichtenplattform, die globale Technologienachrichten und Diskussionen bietet.

GitHubTwitter

Startseite

StartseiteNeuesteBesteFragenZeigenJobs

Ressourcen

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. Alle Rechte vorbehalten.

Making PyPI's test suite faster

125 Punktevon rbanffyvor 5 Tagen

8 comments

boydvor 1 Tag
Throwing cores at the problem with `pytest-xdist` is typically the lowest hanging fruit, but you still hit all the paper cuts the authors mention -- collection, DB fixtures, import time, etc.<p>And, further optimization is <i>really</i> hard when the CI plumbing starts to dominate. For example, the last Warehouse `test` job I checked has 43s of Github Actions overhead for 51s of pytest execution time (half the test action time and approaching 100% overhead).<p>Disclosure: Have been tinkering on a side project trying to provide 90% of these pytest optimizations automatically, but also get &quot;time-to-first-test-failure&quot; down to ~10 seconds (via warm runners, container snapshotting, etc.). Email in profile if anyone would like to swap notes.
cocoflunchyvor 2 Tagen
I don&#x27;t understand why pytest&#x27;s collection is so slow.<p>On our test suite (big django app) it takes about 15s to collect tests. So much that we added a util using ripgrep to find the file and pass it as an argument to pytest when using `pytest -k &lt;testname&gt;`.
评论 #43962054 未加载
评论 #43960519 未加载
评论 #43961168 未加载
评论 #43960438 未加载
nine_kvor 1 Tag
One thing not mentioned here is putting your test database on a RAM disk, aka tmpfs. This significantly speeds up all DB-related tests that use transactions, fixture loading, and migrations.<p>In most distros, &#x2F;tmp is mounted as tmpfs, but YMMV.
qzncvor 1 Tag
I generally try to avoid mocking completely. However, speeding up tests is an appropriate use. If someone changes the implementation the mock usually simply doesn&#x27;t apply and the test still works as intended.<p>For example, a great speed optimization in our tests recently was to mock time.sleep.<p>Why do we have so many sleeps? This is testing a test framework for embedded devices where there is plenty of fiddling-then-wait-for-the-hardware.<p>I also mocked some file system accesses. Unit testing is about our application logic and not about Linux kernel behavior anyways.
NeutralForestvor 2 Tagen
Pretty good article, it&#x27;s really a challenge to properly isolate DB operations during testing so having a difference instance per worker is nice. I remember trying to use different schemas (not instances) but I had a hard time to isolate roles as well.
评论 #43963295 未加载
throwme_123vor 2 Tagen
Is Trail of Bits transitioning out of &quot;crypto&quot;?<p>Imho, they are one of the best auditors out there for smart contracts. Wouldn&#x27;t be surprising to see some of these talented teams find bigger markets.
评论 #43964231 未加载
评论 #43974772 未加载
评论 #43966993 未加载
ustadvor 2 Tagen
The article uses pytest - does anyone have similar tips when using pythons builtin unittest?
评论 #43960236 未加载
评论 #43961176 未加载
bgwaltervor 2 Tagen
I get that pytest has features that unittest does not, but how is scanning for test files in a directory considered appropriate for what is called a high security application in the article?<p>For high security applications the test suite should be boring and straightforward. pytest is full of magic, which makes it so slow.<p>Python in general has become so complex, informally specified and bug ridden that it only survives because of AI while silencing critics in their bubble.<p>The complexity includes PSF development processes, which lead to:<p><a href="https:&#x2F;&#x2F;www.schneier.com&#x2F;blog&#x2F;archives&#x2F;2024&#x2F;08&#x2F;leaked-github-python-token.html" rel="nofollow">https:&#x2F;&#x2F;www.schneier.com&#x2F;blog&#x2F;archives&#x2F;2024&#x2F;08&#x2F;leaked-github...</a>
评论 #43961104 未加载
评论 #43965151 未加载
评论 #43964211 未加载
评论 #43963482 未加载
评论 #43961754 未加载