Skip to content

Commit

Permalink
Add cpu and gpu markers to tests to be able to explicitly choose them
Browse files Browse the repository at this point in the history
Signed-off-by: Samet Akcay <samet.akcay@intel.com>
  • Loading branch information
samet-akcay committed Dec 12, 2024
1 parent 40d27e9 commit a960a18
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/actions/pytest/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ runs:
# Set device-specific pytest arguments
if [ "${{ inputs.device }}" = "cpu" ]; then
DEVICE_ARGS="--markers='not gpu'"
DEVICE_ARGS="-m cpu"
else
DEVICE_ARGS=""
DEVICE_ARGS="-m 'cpu or gpu'" # Run all tests on GPU
fi
# Run pytest
Expand All @@ -150,7 +150,7 @@ runs:
--timeout=${{ inputs.max-test-time }} \
--verbosity=0 \
--durations-only \
$DEVICE_ARGS
${DEVICE_ARGS}
# Store test result and duration
exit_code=$?
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ skips = ["B101"]
addopts = ["--strict-markers", "--strict-config", "--showlocals", "-ra"]
testpaths = "tests"
pythonpath = "src"
markers = [
"gpu: marks tests that require GPU",
"cpu: marks tests that can run on CPU only (default)",
]


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ def checkpoint(model_name: str) -> Path:
return _ckpt_path

return checkpoint


def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
"""Automatically mark tests as 'cpu' unless they're marked as 'gpu'."""
for item in items:
if not any(marker.name == "gpu" for marker in item.iter_markers()):
item.add_marker(pytest.mark.cpu)

0 comments on commit a960a18

Please sign in to comment.