Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest pyproject.toml configuration to ignore a specific path

Are there any ways to set a path to ignore in pyproject.toml like

#pyproject.toml
[tool.pytest.ini_options]
ignore = ["path/to/test"]

instead of using addopts:

#pyproject.toml
[tool.pytest.ini_options]
addopts = "--ignore=path/to/test"   
like image 841
Yauhen Mardan Avatar asked Jul 07 '21 13:07

Yauhen Mardan


People also ask

What is TOML in pyproject?

As the file extension suggests, pyproject.toml is a TOML file. It contains separate sections for different tools. Black is using the [tool.black] section. The option keys are the same as long names of options on the command line.

How to use pytest in structures that don't have a configuration file?

This allows the use of pytest in structures that are not part of a package and don’t have any particular configuration file. If no args are given, pytest collects test below the current working directory and also starts determining the rootdir from there. pytest.ini: will always match and take precedence, even if empty.

How to run specific test method from specific test file in pytest?

Run specific test method. To run specific test method from a specific test file, we can type. pytest test_pytestOptions.py::test_api -sv. This above will run the test method test_api () from file test_pyTestOptions.py.

How to find the root directory of a pytest project?

If no setup.py was found, look for pytest.ini, pyproject.toml, tox.ini, and setup.cfg in each of the specified args and upwards. If one is matched, it becomes the configfile and its directory becomes the rootdir. If no configfile was found and no configuration argument is passed, use the already determined common ancestor as root directory.


Video Answer


1 Answers

Use the following in pyproject.toml

norecursedirs = [
    "path/to/test/*",
]
like image 188
Eptarch Avatar answered Oct 19 '22 18:10

Eptarch