Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cuda_core/tests/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,30 @@ by `cuCtxSynchronize()` before popping the context. Tests should not rely on
that as a substitute for cleaning up explicitly: prefer context managers for
resources whose lifetime fits a single scope, and keep pool lifetimes inside
the test that creates them.

## A per-directory `conftest.py` needs an `__init__.py`
Under pytest's default `prepend` import mode, a test file's `sys.path` entry is
the first parent directory *without* an `__init__.py`; the module is then named
by its path relative to that directory. So for `tests/memory/test_x.py`:

| | `sys.path` entry | module name | `import conftest` finds |
|---|---|---|---|
| no `__init__.py` | `tests/memory` | `test_x` | `tests/memory/conftest.py` |
| with `__init__.py` | `tests` | `memory.test_x` | `tests/conftest.py` |

Adding the `__init__.py` moves the insertion point up one level and solves two problems at once:

1. Many modules do `from conftest import <helper>`, meaning the root
`tests/conftest.py`. Keeping the subdirectory off `sys.path` is what makes
that unambiguous. Otherwise a new per-directory `conftest.py` silently
captures the name and the import fails with `ImportError: cannot import name
...` — reported in the *other* modules in that directory, not in the file you
added.
2. Module names become hierarchical, so a basename reused under another
directory cannot collide. Flat names make `graph/test_memory.py` alongside
`tests/test_memory.py` an "import file mismatch" error.

Split the two kinds of shared test code accordingly: fixtures and hooks go in
`conftest.py`, which pytest discovers and nothing imports by name; constants and
helper functions go in `tests/helpers/`, which tests import explicitly. Following
that split also keeps the name collision from mattering in the first place.
Empty file.
Loading