Skip to content

Commit 24d5072

Browse files
authored
ci: add no extra flag (#653)
* ci: refactor extra grouping by adding no-extra flag * ci: add default markers
1 parent 237279a commit 24d5072

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
include:
7171
- name: base
7272
extras: ""
73-
mark_filter: "cpu and not slow and not style and not requires_intel and not requires_lmharness and not requires_rapidata"
73+
mark_filter: "no_extras"
7474
- name: lmharness
7575
extras: "--extra lmharness"
7676
mark_filter: "requires_lmharness"
@@ -83,6 +83,7 @@ jobs:
8383
HF_HOME: ${{ github.workspace }}/.cache/huggingface
8484
HF_DATASETS_CACHE: ${{ github.workspace }}/.cache/huggingface/datasets
8585
HUGGINGFACE_HUB_CACHE: ${{ github.workspace }}/.cache/huggingface/hub
86+
DEFAULT_MARK_FILTER: "cpu and not slow and not style"
8687

8788
steps:
8889
- name: Checkout code
@@ -138,4 +139,4 @@ jobs:
138139
- name: Run tests with pytest-rerunfailures
139140
run: |
140141
echo "Running tests with up to 3 reruns on failure using $PYTEST_WORKERS workers..."
141-
uv run pytest -n $PYTEST_WORKERS -m "${{ matrix.mark_filter }}" --reruns 3 --reruns-delay 10 --maxfail=1
142+
uv run pytest -n $PYTEST_WORKERS -m "${{ env.DEFAULT_MARK_FILTER }} and ${{ matrix.mark_filter }}" --reruns 3 --reruns-delay 10 --maxfail=1

tests/conftest.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,53 @@
55
# import all fixtures to make them avaliable for pytest
66
from .fixtures import * # noqa: F403, F401
77

8-
HARDWARE_MARKS = {"cpu", "cuda", "multi_gpu"}
8+
DEVICE_MARKS = {
9+
"cpu": "mark test to run on CPU",
10+
"cuda": "mark test to run only on GPU machines",
11+
"multi_gpu": "mark test to run only on multi-GPU machines",
12+
}
13+
EXTRA_MARKS = {
14+
"requires_gptq": "mark test that needs pruna[gptq]",
15+
"requires_awq": "mark test that needs pruna[awq]",
16+
"requires_stable_fast": "mark test that needs pruna[stable-fast]",
17+
"requires_vllm": "mark test that needs pruna[vllm]",
18+
"requires_intel": "mark test that needs pruna[intel]",
19+
"requires_lmharness": "mark test that needs pruna[lmharness]",
20+
"requires_whisper": "mark test that needs pruna[whisper]",
21+
"requires_upscale": "mark test that needs pruna[upscale]",
22+
"requires_rapidata": "mark test that needs pruna[rapidata]",
23+
}
924

1025

1126
def pytest_configure(config: Any) -> None:
1227
"""Configure the pytest markers."""
13-
# Hardware marks
14-
config.addinivalue_line("markers", "cpu: mark test to run on CPU")
15-
config.addinivalue_line("markers", "cuda: mark test to run only on GPU machines")
16-
config.addinivalue_line("markers", "multi_gpu: mark test to run only on multi-GPU machines")
17-
config.addinivalue_line("markers", "high_gpu: mark test to run only on large GPUs") # e.g. H100
28+
# Device marks
29+
for mark, description in DEVICE_MARKS.items():
30+
config.addinivalue_line("markers", f"{mark}: {description}")
31+
config.addinivalue_line("markers", "high_gpu: mark test to run only on large GPUs")
1832
# Dependency marks for external dependencies
19-
config.addinivalue_line("markers", "requires_gptq: mark test that needs pruna[gptq]")
20-
config.addinivalue_line("markers", "requires_awq: mark test that needs pruna[awq]")
21-
config.addinivalue_line("markers", "requires_stable_fast: mark test that needs pruna[stable-fast]")
22-
config.addinivalue_line("markers", "requires_vllm: mark test that needs pruna[vllm]")
23-
config.addinivalue_line("markers", "requires_intel: mark test that needs pruna[intel]")
24-
config.addinivalue_line("markers", "requires_lmharness: mark test that needs pruna[lmharness]")
25-
config.addinivalue_line("markers", "requires_whisper: mark test that needs pruna[whisper]")
26-
config.addinivalue_line("markers", "requires_upscale: mark test that needs pruna[upscale]")
27-
config.addinivalue_line("markers", "requires_rapidata: mark test that needs pruna[rapidata]")
33+
for mark, description in EXTRA_MARKS.items():
34+
config.addinivalue_line("markers", f"{mark}: {description}")
35+
config.addinivalue_line("markers", "no_extras: mark test that runs without optional dependency extras")
2836
# Category marks
2937
config.addinivalue_line("markers", "slow: mark test that run rather long")
3038
config.addinivalue_line("markers", "style: mark test that only check style")
3139
config.addinivalue_line("markers", "integration: mark test that is an integration test")
3240

3341

42+
@pytest.hookimpl(tryfirst=True)
3443
def pytest_collection_modifyitems(session: Any, config: Any, items: list) -> None:
3544
"""Hook that is called after test collection."""
3645
selected = []
3746
deselected = []
3847
for item in items:
3948
# Auto-tag unmarked tests as CPU
40-
if not any(mark in item.keywords for mark in HARDWARE_MARKS):
49+
if not any(mark in item.keywords for mark in DEVICE_MARKS):
4150
item.add_marker(pytest.mark.cpu)
51+
# Auto-tag tests that do not require optional dependency extras. This
52+
# keeps the default CI selection positive as new extras are added.
53+
if not any(mark.name in EXTRA_MARKS for mark in item.iter_markers()):
54+
item.add_marker(pytest.mark.no_extras)
4255
# device_parametrized generates cpu/cuda/accelerate variants for every
4356
# algorithm test, even when the algorithm's runs_on excludes that device.
4457
# The incompatible variants get collected by the CI (e.g. -m "cpu") and

0 commit comments

Comments
 (0)