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.
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://jupytext.readthedocs.io/en/latest/" rel="nofollow">https://jupytext.readthedocs.io/en/latest/</a>
[1]: <a href="https://stackoverflow.com/a/56813896/212538" rel="nofollow">https://stackoverflow.com/a/56813896/212538</a>
You can also use my article to learn a bit about testing with Pytest! <a href="https://stribny.name/blog/pytest/" rel="nofollow">https://stribny.name/blog/pytest/</a>
A couple recent related podcasts on Pytest with co-authors:<p>- <a href="https://testandcode.com/195" rel="nofollow">https://testandcode.com/195</a><p>- <a href="https://talkpython.fm/episodes/show/407/pytest-tips-and-tricks-for-better-testing" rel="nofollow">https://talkpython.fm/episodes/show/407/pytest-tips-and-tric...</a>
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.
You can also consider using CodiumAI to create tests right inside your IDE.
<a href="https://www.codium.ai" rel="nofollow">https://www.codium.ai</a><p><a href="https://plugins.jetbrains.com/plugin/21206-codiumai--meaningful-tests-in-python-powered-by-testgpt" rel="nofollow">https://plugins.jetbrains.com/plugin/21206-codiumai--meaning...</a><p><a href="https://marketplace.visualstudio.com/items?itemName=Codium.codium" rel="nofollow">https://marketplace.visualstudio.com/items?itemName=Codium.c...</a>
Also, run your tests in watch mode using entr or pytest-watch [0] for faster feedback.<p>[0] <a href="https://pypi.org/project/pytest-watch/" rel="nofollow">https://pypi.org/project/pytest-watch/</a>