|
5 | 5 | # import all fixtures to make them avaliable for pytest |
6 | 6 | from .fixtures import * # noqa: F403, F401 |
7 | 7 |
|
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 | +} |
9 | 24 |
|
10 | 25 |
|
11 | 26 | def pytest_configure(config: Any) -> None: |
12 | 27 | """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") |
18 | 32 | # 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") |
28 | 36 | # Category marks |
29 | 37 | config.addinivalue_line("markers", "slow: mark test that run rather long") |
30 | 38 | config.addinivalue_line("markers", "style: mark test that only check style") |
31 | 39 | config.addinivalue_line("markers", "integration: mark test that is an integration test") |
32 | 40 |
|
33 | 41 |
|
| 42 | +@pytest.hookimpl(tryfirst=True) |
34 | 43 | def pytest_collection_modifyitems(session: Any, config: Any, items: list) -> None: |
35 | 44 | """Hook that is called after test collection.""" |
36 | 45 | selected = [] |
37 | 46 | deselected = [] |
38 | 47 | for item in items: |
39 | 48 | # 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): |
41 | 50 | 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) |
42 | 55 | # device_parametrized generates cpu/cuda/accelerate variants for every |
43 | 56 | # algorithm test, even when the algorithm's runs_on excludes that device. |
44 | 57 | # The incompatible variants get collected by the CI (e.g. -m "cpu") and |
|
0 commit comments