Skip to content
Latchkey

pytest "ERROR: file or directory not found" / rootdir Problems

pytest computes a rootdir from where it runs and the config files it finds. When CI runs from an unexpected directory, the rootdir is wrong - config and conftest.py aren’t loaded, and paths don’t resolve.

What this error means

pytest reports ERROR: file or directory not found, or behaves as if your config doesn’t exist (markers unknown, plugins off, fixtures missing). The printed rootdir: line is not where you expect.

pytest output
ERROR: file or directory not found: tests
rootdir: /home/runner/work/repo
configfile: (none found)

Common causes

Running from the wrong working directory

CI invokes pytest from a parent or subdirectory where the test path doesn’t exist, so the path argument is "not found" and rootdir is computed elsewhere.

No config file at the expected level

pytest derives rootdir from the nearest pyproject.toml/pytest.ini/tox.ini/setup.cfg. If none is where you think, config-driven behavior silently turns off.

How to fix it

Run from the repo root with explicit config

Terminal
cd "$GITHUB_WORKSPACE"
pytest -c pyproject.toml tests/

Pin rootdir and testpaths in config

Make the layout explicit so rootdir is stable regardless of where CI starts.

pyproject.toml
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-ra"

Verify what pytest detected

  1. Read the rootdir: and configfile: lines pytest prints at startup.
  2. If configfile: (none found), your config isn’t where pytest looked.
  3. Pass -c <config> and an explicit test path to remove ambiguity.

How to prevent it

  • Run pytest from a consistent working directory in CI.
  • Keep a single config file at the repo root with testpaths set.
  • Check the startup rootdir:/configfile: lines when behavior seems off.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →