Stopping pytest from Looking in the Wrong Places

Did you know that one of the definitions of “recurse” is to swear at your code twice? Well, no. But, it does mean to traverse subdirectories. In the case of pytest, test discovery traverses many directories recursively. But there are some directories you just know you don’t want pytest looking in.

The default setting for norecurse is ’.* build dist CVS _darcs {arch} and *.egg. Having ’.*’ is a good reason to name your virtual environment ’.venv’, because all directories starting with a dot will not be traversed. However, I have a habit of naming it venv, so I could add that to norecursedirs.

In the case of the Tasks project, you could list src in there also, because having pytest look for test ...

Get Python Testing with pytest now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.