Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell py.test to skip certain directories?

People also ask

How do I ignore a folder in pytest?

The --ignore-glob option allows to ignore test file paths based on Unix shell-style wildcards. If you want to exclude test-modules that end with _01.py , execute pytest with --ignore-glob='*_01.py' .

What is the name of the directory that pytest will look at to detect tests?

With no arguments, pytest looks at the current working directory (or some other preconfigured directory) and all subdirectories for test files and runs the test code it finds. Running all test files in the current directory. We can run a specific test file by giving its name as an argument.

How do I ignore warnings in pytest?

Disabling warnings summary Although not recommended, you can use the --disable-warnings command-line option to suppress the warning summary entirely from the test run output.


py.test --ignore=somedir worked for me


If you have several directories with different parents you can specify different --ignore parameters:

py.test --ignore=somedir --ignore=otherdir --ignore=etcdir

  • new option: --ignore will prevent specified path from collection.
    Can be specified multiple times.

I solved the mystery: If a pytest section is found in one of the possible config files (pytest.ini, tox.ini and setup.cfg), pytest will not look for any others so be sure you define the py.test options in a single file.

I would suggest using setup.cfg.


You can use

py.test -k 'not third'

that excludes all 'third' directory contents.


In my case, the issue was the missing wildcard. The following works for me:

[tool:pytest]
norecursedirs = subpath/*

whereas just norecursedirs = subpath didn't.