| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
原始链接: https://news.ycombinator.com/item?id=43931237
Hacker News 的讨论围绕着如何加快 Python 的 Pytest 测试套件,特别是针对 Django 应用这样的大型项目。常见的瓶颈包括缓慢的测试收集、数据库操作(迁移、fixture 加载)以及 CI/CD 开销。 讨论中提出的解决方案包括使用 `pytest-xdist` 进行并行执行,预迁移的 SQLite 测试数据库,缓存测试环境,优化导入语句以及模拟 `time.sleep` 等缓慢操作。 几位评论者强调了数据库设置上花费的大量时间,提倡使用模板数据库或内存盘。其他人强调了测试分析的重要性,以识别具体的性能瓶颈,例如过度庞大的图片创建。一些人讨论了 Python 及其生态系统更广泛的复杂性,而另一些人则捍卫了它持续的相关性和能力,尤其是在科学计算和系统管理方面。总的来说,讨论强调需要采取多方面的方法来优化 Python 测试套件,解决架构和代码级别的低效率问题。
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
And, further optimization is really 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).
Disclosure: Have been tinkering on a side project trying to provide 90% of these pytest optimizations automatically, but also get "time-to-first-test-failure" down to ~10 seconds (via warm runners, container snapshotting, etc.). Email in profile if anyone would like to swap notes.
reply