Skip to content

Commit 9b4e94d

Browse files
committed
address review feedback
1 parent 07a9f63 commit 9b4e94d

4 files changed

Lines changed: 28 additions & 127 deletions

File tree

‎cuda_core/tests/AGENTS.md‎

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,27 @@ that as a substitute for cleaning up explicitly: prefer context managers for
6666
resources whose lifetime fits a single scope, and keep pool lifetimes inside
6767
the test that creates them.
6868

69-
## Shared test code: `conftest.py` vs `tests/helpers/`
70-
71-
`conftest.py` is **not a regular module** — pytest discovers it automatically
72-
and injects its fixtures; nothing should import it by name with
73-
`from conftest import ...`. Keeping it off the import path is what allows
74-
pytest to build the correct fixture hierarchy from multiple `conftest.py` files
75-
at different directory levels. See the pytest docs:
76-
https://docs.pytest.org/en/stable/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files
77-
78-
Keep the two kinds of shared test code in their proper places:
79-
80-
- **Fixtures and hooks** go in `conftest.py`. Tests receive them through
81-
pytest's dependency injection; they never need to import `conftest` directly.
82-
- **Plain helper functions and constants** go in `tests/helpers/`. Tests that
83-
need them import from there explicitly, e.g.
69+
## Shared test support
70+
71+
See also: https://docs.pytest.org/en/stable/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files
72+
73+
Follow these rules when adding or moving shared test code:
74+
75+
- Never import from a `conftest.py`.
76+
- Put suite-wide fixtures and pytest hooks in `tests/conftest.py`. Put fixtures
77+
needed only by one test subtree in that subtree's nearest `conftest.py`.
78+
- Put a pytest hook in a nested `conftest.py` only if pytest supports that hook
79+
there. If the hook receives suite-wide data, explicitly limit its effects to
80+
the intended subtree.
81+
- Code used only to implement fixtures or hooks may remain in the same
82+
`conftest.py`. Put functions and constants imported by test modules in
83+
`tests/helpers/` instead.
84+
- Import helpers explicitly from the test root, for example:
8485
`from helpers.memory import create_managed_memory_resource_or_skip`.
85-
86-
### Adding a per-directory `conftest.py`
87-
88-
When you add a `conftest.py` under a subdirectory (e.g. `tests/memory/`),
89-
pytest automatically makes its fixtures available to tests in that directory
90-
and propagates fixtures from parent `conftest.py` files downward — no
91-
`__init__.py` is required for this to work.
92-
93-
The suite uses pytest's default `prepend` import mode
94-
(https://docs.pytest.org/en/stable/explanation/goodpractices.html#choosing-an-import-mode).
95-
`pytest.ini` sets `pythonpath = tests` so that every test file, regardless of
96-
how deep it sits, can resolve `from helpers.xxx import ...` against the
97-
`tests/` root. Without that setting, test files in subdirectories without
98-
`__init__.py` would get their own subdirectory prepended to `sys.path` instead
99-
of `tests/`, and the `helpers` package would not be found.
86+
- Fixtures in a nested `conftest.py` are available to tests in its directory
87+
and descendants; fixtures from applicable parent `conftest.py` files remain
88+
available.
89+
- Do not add `__init__.py` solely because a test directory contains a
90+
`conftest.py`.
91+
- In directories without `__init__.py`, keep test-module basenames unique
92+
within this test suite.

‎cuda_core/tests/helpers/cuda_helpers.py‎

Lines changed: 0 additions & 92 deletions
This file was deleted.

‎cuda_core/tests/memory/test_managed_ops.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ def _page_base(buf):
3737

3838

3939
def _skip_if_raw_managed_alloc_unsupported(device):
40-
# Raw `cuMemAllocManaged` capability — distinct from conftest's
41-
# `skip_if_managed_memory_unsupported`, which gates `ManagedMemoryResource`
42-
# pool creation. Used by tests that exercise `DummyUnifiedMemoryResource`.
40+
# Raw `cuMemAllocManaged` capability — distinct from
41+
# `helpers.memory.skip_if_managed_memory_unsupported`, which gates
42+
# `ManagedMemoryResource` pool creation. Used by tests that exercise
43+
# `DummyUnifiedMemoryResource`.
4344
try:
4445
if not device.properties.managed_memory:
4546
pytest.skip("Device does not support managed memory operations")

‎cuda_core/tests/test_launcher.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import ctypes
55

66
import helpers
7-
from cuda_python_test_helpers.marks import requires_module
7+
from cuda_python_test_helpers.marks import requires_module, skipif_need_cuda_headers
88
from helpers.misc import StreamWrapper
99

1010
try:
@@ -13,7 +13,6 @@
1313
cp = None
1414
import numpy as np
1515
import pytest
16-
from cuda_python_test_helpers.marks import skipif_need_cuda_headers
1716

1817
from cuda.core import (
1918
Device,

0 commit comments

Comments
 (0)