## TL;DR

This error means two test files (or a test file and a source file) share the same basename, like `tests/a/utils.py` and `tests/b/utils.py`, and neither directory has an `__init__.py`, so pytest cannot tell them apart as modules. Fix it by adding `__init__.py` files to make packages explicit, by renaming one file, or by setting `--import-mode=importlib` so pytest imports by file path instead of by guessed module name.

## The query

```text
pytest import file mismatch error: how to fix
```

## Use this when

- pytest aborts during collection with "import file mismatch".
- You added a new test directory and collection broke.

## Not for

- `ModuleNotFoundError` for a real dependency; that is a different problem.
- Coverage or plugin configuration issues.

## Steps

1. Read the full error; pytest names both colliding files. Expected output: you see the two paths with the same basename.
2. Check whether their directories contain `__init__.py`. Expected output: you know which dirs are plain directories vs packages.
3. Add `__init__.py` to the test directories (or rename one of the colliding files). Expected output: basenames now resolve to distinct module paths.
4. Alternatively, run with `pytest --import-mode=importlib` and re-run. Expected output: collection succeeds without the mismatch.
5. Re-run the full suite to confirm nothing else collided. Expected output: collection completes, tests run.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_ktd6iQssg2ya5aQvPAT_8A
