pytest ignore directory: --ignore, norecursedirs and collect_ignore
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/.

–ignore and –ignore-glob
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:
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--ignore=tests/integration"Ignore a directory in pyproject.toml
norecursedirs takes directory names or patterns:
[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:
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.

collect_ignore in conftest.py
# 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.
What Supercov adds
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. For the tools side by
side, see Python code coverage.
More coverage guides
- Jest coverageThreshold: global, per-folder and per-file
- JaCoCo aggregate report for multi-module Maven and Gradle builds
- Merge coverage reports from shards: Vitest, Jest and coverage.py
- Statement vs branch coverage, with decision, line and path coverage
- JaCoCo report not generated: the causes in Maven and Gradle
- Kover exclude: classes, packages and generated code
- sonar.coverage.exclusions: why SonarQube ignores your JaCoCo excludes
- istanbul ignore next vs c8 ignore next: every hint, measured
- Go test coverage exclude: files, packages and mocks
- Jest coverage exclude: files, folders and lines
- pytest coverage exclude: omit files, folders and lines
- Vitest coverage exclude: files, folders and lines
- JaCoCo exclude in Maven and Gradle: packages, classes and generated code