|
| 1 | +"""Pytest configuration for vivarium-build-utils' own test suite. |
| 2 | +
|
| 3 | +This deliberately duplicates the ``--runslow`` and ``--runweekly`` handling |
| 4 | +from ``vivarium.testing_utils``' pytest plugin. vbu cannot depend on |
| 5 | +vivarium-testing-utils to pick up that plugin, because vtu depends on vbu; |
| 6 | +registering the options here lets the shared Jenkins ``pytest`` invocations |
| 7 | +(which pass ``--runslow`` and ``--runweekly``) run against vbu without erroring |
| 8 | +on an unrecognized option. |
| 9 | +""" |
| 10 | + |
| 11 | +import pytest |
| 12 | + |
| 13 | + |
| 14 | +def pytest_addoption(parser: pytest.Parser) -> None: |
| 15 | + parser.addoption("--runslow", action="store_true", default=False, help="run slow tests") |
| 16 | + parser.addoption( |
| 17 | + "--runweekly", action="store_true", default=False, help="run weekly tests" |
| 18 | + ) |
| 19 | + |
| 20 | + |
| 21 | +def pytest_configure(config: pytest.Config) -> None: |
| 22 | + config.addinivalue_line("markers", "slow: mark test as slow to run") |
| 23 | + config.addinivalue_line("markers", "weekly: mark test as a weekly test") |
| 24 | + |
| 25 | + |
| 26 | +def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None: |
| 27 | + if not config.getoption("--runslow"): |
| 28 | + skip_slow = pytest.mark.skip(reason="need --runslow option to run") |
| 29 | + for item in items: |
| 30 | + if item.get_closest_marker("slow"): |
| 31 | + item.add_marker(skip_slow) |
| 32 | + |
| 33 | + if not config.getoption("--runweekly"): |
| 34 | + skip_weekly = pytest.mark.skip(reason="need --runweekly option to run") |
| 35 | + for item in items: |
| 36 | + if item.get_closest_marker("weekly"): |
| 37 | + item.add_marker(skip_weekly) |
0 commit comments