TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Pytest Tips and Tricks

116 pointsby giladabout 2 years ago

9 comments

systemvoltageabout 2 years ago
I have a personal gripe against Pytest. It extremely implicit, does so many things behind the scenes that it makes learning the library difficult for new comers. I had a hard time. For example, fixtures are passed as arguments in function. You can't use IDE tools to find out where they are passed from. There are dozens of things that go completely against the philosophy of Python: Explicit is better than implicit. Pytest is full of magic, it irritates me. The kind of questions asked on Stack Overflow reflects my personal experience with libraries of this kind. So many people are confused.
评论 #35257324 未加载
评论 #35257388 未加载
评论 #35257114 未加载
评论 #35257931 未加载
评论 #35256940 未加载
评论 #35260573 未加载
评论 #35264918 未加载
japanuspusabout 2 years ago
My favorite pytest trick: Using jupytext notebooks as tests.<p>I always use a notebook for notes and experiments when building python packages. By using `jupytext`[0] I can store the notebook as a commented python-file, which I can run from a parametrized test that runs all notebooks in a given folder [1]. Adding a few `asserts`, this gives you reasonable test coverage right from the start.<p>[0]: <a href="https:&#x2F;&#x2F;jupytext.readthedocs.io&#x2F;en&#x2F;latest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jupytext.readthedocs.io&#x2F;en&#x2F;latest&#x2F;</a> [1]: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;56813896&#x2F;212538" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;56813896&#x2F;212538</a>
petr25102018about 2 years ago
You can also use my article to learn a bit about testing with Pytest! <a href="https:&#x2F;&#x2F;stribny.name&#x2F;blog&#x2F;pytest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;stribny.name&#x2F;blog&#x2F;pytest&#x2F;</a>
brianzelipabout 2 years ago
A couple recent related podcasts on Pytest with co-authors:<p>- <a href="https:&#x2F;&#x2F;testandcode.com&#x2F;195" rel="nofollow">https:&#x2F;&#x2F;testandcode.com&#x2F;195</a><p>- <a href="https:&#x2F;&#x2F;talkpython.fm&#x2F;episodes&#x2F;show&#x2F;407&#x2F;pytest-tips-and-tricks-for-better-testing" rel="nofollow">https:&#x2F;&#x2F;talkpython.fm&#x2F;episodes&#x2F;show&#x2F;407&#x2F;pytest-tips-and-tric...</a>
cocoflunchyabout 2 years ago
Does anyone have tips on how to speed up test collection in pytest? In our django app (~5000 tests) it takes about 30s to run a single test with `-k testname` when the actual time spent in the test is on the order of a few hundred milliseconds.<p>It hangs forever on the `collecting ...` phase.
评论 #35258405 未加载
评论 #35259151 未加载
评论 #35259951 未加载
itamarcodeabout 2 years ago
You can also consider using CodiumAI to create tests right inside your IDE. <a href="https:&#x2F;&#x2F;www.codium.ai" rel="nofollow">https:&#x2F;&#x2F;www.codium.ai</a><p><a href="https:&#x2F;&#x2F;plugins.jetbrains.com&#x2F;plugin&#x2F;21206-codiumai--meaningful-tests-in-python-powered-by-testgpt" rel="nofollow">https:&#x2F;&#x2F;plugins.jetbrains.com&#x2F;plugin&#x2F;21206-codiumai--meaning...</a><p><a href="https:&#x2F;&#x2F;marketplace.visualstudio.com&#x2F;items?itemName=Codium.codium" rel="nofollow">https:&#x2F;&#x2F;marketplace.visualstudio.com&#x2F;items?itemName=Codium.c...</a>
skimdeskabout 2 years ago
Also, run your tests in watch mode using entr or pytest-watch [0] for faster feedback.<p>[0] <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;pytest-watch&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;pytest-watch&#x2F;</a>
zikohhabout 2 years ago
pytest-repeat for flaky tests!
fud101about 2 years ago
Why does everyone want money for this kind of content. It&#x27;s exhausting.
评论 #35256632 未加载
评论 #35256788 未加载
评论 #35256560 未加载
评论 #35256619 未加载