|
1 | 1 | """Shared fixtures for tests data.""" |
2 | 2 |
|
| 3 | +import logging |
3 | 4 | from collections.abc import Sequence |
4 | 5 | from pathlib import Path |
5 | 6 | from types import SimpleNamespace |
6 | 7 |
|
| 8 | +import niwrap |
7 | 9 | import pytest |
8 | 10 |
|
9 | 11 |
|
10 | 12 | def pytest_collection_modifyitems(items: Sequence[pytest.Item]) -> None: |
11 | 13 | """Apply appropriate markers based on test location.""" |
| 14 | + markers = {"unit", "integration", "full_pipeline"} |
| 15 | + |
12 | 16 | for item in items: |
13 | 17 | test_path = Path(item.fspath) |
| 18 | + for marker in markers & set(test_path.parts): |
| 19 | + item.add_marker(getattr(pytest.mark, marker)) |
| 20 | + |
| 21 | + |
| 22 | +def pytest_addoption(parser: pytest.Parser) -> None: |
| 23 | + """Add option(s) to pytest parser.""" |
| 24 | + parser.addoption( |
| 25 | + "--runner", |
| 26 | + action="store", |
| 27 | + default="docker", |
| 28 | + help="Styx runner type to use: ['local', 'docker', 'singularity']", |
| 29 | + ) |
| 30 | + |
14 | 31 |
|
15 | | - if "unit" in test_path.parts: |
16 | | - item.add_marker(pytest.mark.unit) |
| 32 | +@pytest.fixture(scope="session", autouse=True) |
| 33 | +def niwrap_runner( |
| 34 | + request: pytest.FixtureRequest, |
| 35 | + tmp_path_factory: pytest.TempPathFactory, |
| 36 | +) -> niwrap.Runner: |
| 37 | + """Globally set test niwrap runner.""" |
| 38 | + # Set up niwrap runner |
| 39 | + match request.config.getoption("--runner").lower(): |
| 40 | + case "docker": |
| 41 | + niwrap.use_docker() |
| 42 | + case "singularity": |
| 43 | + niwrap.use_singularity() |
| 44 | + case _: |
| 45 | + niwrap.use_local() |
| 46 | + runner = niwrap.get_global_runner() |
| 47 | + runner.data_dir = tmp_path_factory.mktemp("styx_tmp") |
| 48 | + # Set up logging for debugging |
| 49 | + logger = logging.getLogger(runner.logger_name) |
| 50 | + logger.setLevel(logging.DEBUG) |
| 51 | + return runner |
17 | 52 |
|
18 | 53 |
|
19 | 54 | @pytest.fixture |
|
0 commit comments