"""Pytest plugin: marker-based changed-lambda filtering for integration tests. Registered as a ``pytest11`` entry point, so any repo that installs ``test_fixtures`` gets it automatically. It registers the ``lambda_name`` marker and deselects tests whose lambda is not named in the ``LAMBDA_FUNCTION_NAMES`` environment variable — the changed-lambda CI filter — without each repo hand-writing ``pytest_collection_modifyitems`` in its ``conftest.py``. Per-repo configuration is a single pytest ini option: [tool.pytest.ini_options] always_deselect_lambdas = ['state-machine'] Tags listed there only run when explicitly named in ``LAMBDA_FUNCTION_NAMES`` (e.g. a slow step-function suite). When no ``lambda_name`` markers are present the plugin is a no-op, so it is safe for non-integration suites too. """ import os import pytest from test_fixtures.pytest_markers import deselect_items_by_tag MARKER_NAME = 'lambda_name' ENV_VAR = 'LAMBDA_FUNCTION_NAMES' INI_ALWAYS_DESELECT = 'always_deselect_lambdas' def pytest_configure(config: pytest.Config) -> None: config.addinivalue_line( 'markers', f'{MARKER_NAME}(name): the lambda function directory name this test ' "covers (e.g. 'finalize-job').", ) def pytest_addoption(parser: pytest.Parser) -> None: parser.addini( INI_ALWAYS_DESELECT, type='args', default=[], help=( 'lambda_name tags that only run when explicitly named in ' f'{ENV_VAR} (e.g. a step-function suite that needs a live state ' 'machine).' ), ) def active_tags_from_env() -> set[str]: """Parse ``LAMBDA_FUNCTION_NAMES`` into a set of tags (empty = run all).""" raw = os.environ.get(ENV_VAR, '').strip() if not raw: return set() return {name.strip() for name in raw.split(',') if name.strip()} def pytest_collection_modifyitems( config: pytest.Config, items: list[pytest.Item] ) -> None: deselect_items_by_tag( config=config, items=items, marker_name=MARKER_NAME, active_tags=active_tags_from_env(), always_deselect_when_missing=set(config.getini(INI_ALWAYS_DESELECT)), )