Skip to content

Commit a960a18

Browse files
committed
Add cpu and gpu markers to tests to be able to explicitly choose them
Signed-off-by: Samet Akcay <[email protected]>
1 parent 40d27e9 commit a960a18

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

.github/actions/pytest/action.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ runs:
137137
138138
# Set device-specific pytest arguments
139139
if [ "${{ inputs.device }}" = "cpu" ]; then
140-
DEVICE_ARGS="--markers='not gpu'"
140+
DEVICE_ARGS="-m cpu"
141141
else
142-
DEVICE_ARGS=""
142+
DEVICE_ARGS="-m 'cpu or gpu'" # Run all tests on GPU
143143
fi
144144
145145
# Run pytest
@@ -150,7 +150,7 @@ runs:
150150
--timeout=${{ inputs.max-test-time }} \
151151
--verbosity=0 \
152152
--durations-only \
153-
$DEVICE_ARGS
153+
${DEVICE_ARGS}
154154
155155
# Store test result and duration
156156
exit_code=$?

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ skips = ["B101"]
291291
addopts = ["--strict-markers", "--strict-config", "--showlocals", "-ra"]
292292
testpaths = "tests"
293293
pythonpath = "src"
294+
markers = [
295+
"gpu: marks tests that require GPU",
296+
"cpu: marks tests that can run on CPU only (default)",
297+
]
294298

295299

296300
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

tests/conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,10 @@ def checkpoint(model_name: str) -> Path:
101101
return _ckpt_path
102102

103103
return checkpoint
104+
105+
106+
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
107+
"""Automatically mark tests as 'cpu' unless they're marked as 'gpu'."""
108+
for item in items:
109+
if not any(marker.name == "gpu" for marker in item.iter_markers()):
110+
item.add_marker(pytest.mark.cpu)

0 commit comments

Comments
 (0)