# pytest ignore directory: --ignore, norecursedirs and collect_ignore > Ignore a directory in pytest with --ignore, --ignore-glob, norecursedirs, testpaths or collect_ignore in conftest.py, and why --ignore=folder matches nothing. Web page: https://supercov.com/blog/pytest-ignore-directory · Published 2026-11-27 All Supercov pages for agents: https://supercov.com/llms.txt · Full text: https://supercov.com/llms-full.txt Every way to skip a folder of tests, collected with pytest 9.2.0, and the three that quietly ignore nothing. To skip a directory, pass its path from where you run pytest: `pytest --ignore=tests/integration`. To skip it every time, put `collect_ignore = ["integration"]` in that folder's parent `conftest.py`, or set `norecursedirs`, which replaces pytest's defaults. A bare `--ignore=integration` matches nothing. ## Ways to ignore tests at a glance | To skip | Use | | --- | --- | | One directory, this run | `pytest --ignore=tests/integration` | | Files by pattern | `pytest --ignore-glob='*slow*'` | | A directory, every run | `collect_ignore = ["integration"]` in `tests/conftest.py` | | Directories by name, every run | `norecursedirs = ["integration", ".*", "build", "venv"]` | | Everything outside `tests/` | `testpaths = ["tests"]` | | One test | `pytest --deselect tests/unit/test_pricing.py::test_rejects_zero` | | Tests by name | `pytest -k 'not slow'` | We collected every setup with pytest 9.2.0 and Python 3.13 on a project with `tests/unit` (3 tests), `tests/integration` (2), a `legacy/tests` folder (1) and a stale copy of a test in `build/lib/tests` (1). With no options, `pytest` collected 6: everything except `build/`. ![A grid of seven pytest setups against four folders, unit, integration, legacy and build. A plain run collects unit, integration and legacy: 6 tests. --ignore=tests/integration: 4. --ignore=integration: still 6. norecursedirs integration also collects build: 5. testpaths tests: 5. collect_ignore integration: 3. Naming tests/integration with --ignore: 2.](https://supercov.com/assets/pytest-ignore-directory-grid-1360.0f41d353f0.webp) *Which folders pytest 9.2.0 collected with each setup.* ## --ignore and --ignore-glob ```sh pytest --ignore=tests/integration --ignore=legacy ``` Each `--ignore` takes a path relative to where you run pytest; repeat it for more. This collected the 3 unit tests. A trailing slash made no difference, but `--ignore=integration` ignored nothing: all 6 tests ran. For a pattern, `--ignore-glob` matches file paths, so `--ignore-glob='*/integration/*'` and `--ignore-glob='*slow*'` both worked; quote the pattern so the shell does not expand it. To keep the option in config, add it to `addopts`: ```toml [tool.pytest.ini_options] testpaths = ["tests"] addopts = "--ignore=tests/integration" ``` ## Ignore a directory in pyproject.toml `norecursedirs` takes directory names or patterns: ```toml [tool.pytest.ini_options] norecursedirs = ["integration", "legacy"] ``` This skipped both directories, and collected the stale `build/lib/tests` copy that the plain run left out. Setting `norecursedirs` replaces the defaults, which include `build`, `dist`, `venv`, `node_modules` and `.*`. Copy those back into the list: ```toml norecursedirs = ["integration", "legacy", ".*", "build", "dist", "venv", "node_modules"] ``` `testpaths = ["tests"]` limits where a plain `pytest` looks, which left out `legacy/` and `build/` at once: 5 tests. ![A diagram of pytest's order: paths you name are always collected, then testpaths, then norecursedirs, which replaces the defaults build, venv and dot folders, then --ignore and collect_ignore. Among the tests collected, -k deselects by name, -m by marker, and --deselect one test.](https://supercov.com/assets/pytest-ignore-directory-flow-1360.fc7256f818.webp) *How pytest picks the tests to run, in the order it applies each option.* ## collect_ignore in conftest.py ```python # tests/conftest.py collect_ignore = ["integration"] collect_ignore_glob = ["*slow*"] ``` Paths are relative to the `conftest.py`, so `integration` here means `tests/integration`. With `collect_ignore` the run collected 3 tests; with `collect_ignore_glob` alone, 4. Being Python, the list can depend on the platform or the Python version. ## Why your pytest ignore isn't working | What we tried | What happened | | --- | --- | | `--ignore=integration` run from the project root | Nothing ignored | | `norecursedirs = ["integration"]` | Integration skipped, `build/` collected | | `pytest tests/integration` with `--ignore=tests/integration` | Both integration tests ran | | `pytest tests/integration` with `norecursedirs` | Both ran: a path you name is collected | | `-m 'not integration'` without a marker on the tests | Nothing deselected | A path given on the command line wins over every ignore. To exclude tests by level with `-m`, mark them first, with `pytestmark = pytest.mark.integration` in the module. ## Ignored tests and coverage Skipping a directory also drops the code only those tests run. With `--cov=shop`, the full run covered 8 of 8 statements; with `--ignore=tests/integration`, 5 of 8, since `ship()` is tested only there. To leave source files out of the report instead, see [pytest coverage exclude](https://supercov.com/blog/pytest-coverage-exclude.md). ## What Supercov adds ```sh npx supercov -- pytest --ignore=tests/integration npx supercov runs latest gaps ``` Supercov runs the same command, ignore options included, and records which test covered each line, with branches and MC/DC. Run the integration directory separately and `npx supercov merge` combines the two runs; see [Merge coverage reports](https://supercov.com/blog/merge-coverage-reports.md). For the tools side by side, see [Python code coverage](https://supercov.com/compare/python-code-coverage.md).