From 0477e0c3d0f7785ba19e83cabd243c15ba102828 Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Fri, 7 Aug 2026 18:36:50 +0200 Subject: [PATCH 1/2] fix: register the infrahub_integration pytest marker under its real name The marker was registered as `infrahub_integraton`, with a missing `i`, but the loader applies `infrahub_integration`. So the marker we use was never registered and the one we register was never used. Every integration test raised a `PytestUnknownMarkWarning`, and collection failed under `--strict-markers`. `pytest --markers` also listed a marker that nothing applies, which is misleading for anyone selecting tests by marker. Turn on `--strict-markers` for our own test run so an unregistered marker fails the build instead of passing silently. --- changelog/1231.fixed.md | 1 + infrahub_sdk/pytest_plugin/plugin.py | 2 +- pyproject.toml | 2 +- tests/unit/pytest_plugin/test_plugin.py | 48 +++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 changelog/1231.fixed.md diff --git a/changelog/1231.fixed.md b/changelog/1231.fixed.md new file mode 100644 index 000000000..c845fa9f4 --- /dev/null +++ b/changelog/1231.fixed.md @@ -0,0 +1 @@ +Register the `infrahub_integration` pytest marker under its real name. It was registered as `infrahub_integraton`, so integration tests raised a `PytestUnknownMarkWarning` on every run and failed to collect under `--strict-markers`. diff --git a/infrahub_sdk/pytest_plugin/plugin.py b/infrahub_sdk/pytest_plugin/plugin.py index 258e7f9c8..aa5f79824 100644 --- a/infrahub_sdk/pytest_plugin/plugin.py +++ b/infrahub_sdk/pytest_plugin/plugin.py @@ -100,7 +100,7 @@ def pytest_configure(config: pytest.Config) -> None: config.addinivalue_line("markers", "infrahub_unit: Unit test for an Infrahub resource, works without dependencies") config.addinivalue_line( "markers", - "infrahub_integraton: Integation test for an Infrahub resource, depends on an Infrahub running instance", + "infrahub_integration: Integration test for an Infrahub resource, depends on an Infrahub running instance", ) config.addinivalue_line("markers", "infrahub_check: Test related to an Infrahub Check") config.addinivalue_line("markers", "infrahub_graphql_query: Test related to an Infrahub GraphQL query") diff --git a/pyproject.toml b/pyproject.toml index 46f9d5333..0bd7f27e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -117,7 +117,7 @@ filterwarnings = [ "ignore:Module already imported so cannot be rewritten", "ignore:Deprecated call to", ] -addopts = "-vs --cov-report term-missing --cov-report xml --dist loadscope" +addopts = "-vs --strict-markers --cov-report term-missing --cov-report xml --dist loadscope" [tool.ty] diff --git a/tests/unit/pytest_plugin/test_plugin.py b/tests/unit/pytest_plugin/test_plugin.py index 01fa38ac7..7f09e78ab 100644 --- a/tests/unit/pytest_plugin/test_plugin.py +++ b/tests/unit/pytest_plugin/test_plugin.py @@ -28,6 +28,54 @@ def test_emptyconfig(pytester: pytest.Pytester) -> None: result.assert_outcomes() +def test_markers_are_registered(pytester: pytest.Pytester) -> None: + """Every marker the plugin applies must be registered, otherwise --strict-markers rejects it.""" + pytester.makefile( + ".yml", + test_markers=""" + --- + version: "1.0" + infrahub_tests: + - resource: "Jinja2Transform" + resource_name: "bgp_config" + tests: + - name: "smoke" + spec: + kind: "jinja2-transform-smoke" + - name: "unit" + spec: + kind: "jinja2-transform-unit-render" + - name: "integration" + spec: + kind: "jinja2-transform-integration" + variables: {} + """, + ) + pytester.makefile( + ".yml", + infrahub_config=""" + --- + jinja2_transforms: + - name: bgp_config + description: "Template for BGP config base" + query: "bgp_sessions" + template_path: "templates/bgp_config.j2" + """, + ) + pytester.makefile(".json", input="{}") + + result = pytester.runpytest("--infrahub-repo-config=infrahub_config.yml", "--strict-markers", "--collect-only") + + assert result.ret == pytest.ExitCode.OK + result.stdout.fnmatch_lines( + [ + "*infrahub_jinja2_transform__bgp_config__smoke*", + "*infrahub_jinja2_transform__bgp_config__unit*", + "*infrahub_jinja2_transform__bgp_config__integration*", + ] + ) + + def test_jinja2_transform_config_missing_directory(pytester: pytest.Pytester) -> None: """Make sure tests raise errors if directories are not found.""" pytester.makefile( From ec8ae227c6ee44178ae5052b4a1e99a5b587f490 Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Mon, 10 Aug 2026 13:19:27 +0200 Subject: [PATCH 2/2] test: cover the resource markers, which strict markers cannot reach The first test only collected Jinja2Transform items, so a typo in the check, graphql query or python transform marker went unnoticed. Collecting the other resource kinds does not help either. `MARKER_MAPPING` is built when the loader is imported, so those marks exist before a config is attached, and `MarkGenerator` only validates a mark when it has one. Compare them against the registered list instead, and keep the collection test for the markers that are applied while collecting. The expected names come from `MARKER_MAPPING`, so a new resource marker is covered on its own. --- tests/unit/pytest_plugin/test_plugin.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/unit/pytest_plugin/test_plugin.py b/tests/unit/pytest_plugin/test_plugin.py index 7f09e78ab..7a1b5db4c 100644 --- a/tests/unit/pytest_plugin/test_plugin.py +++ b/tests/unit/pytest_plugin/test_plugin.py @@ -1,5 +1,7 @@ import pytest +from infrahub_sdk.pytest_plugin.loader import MARKER_MAPPING + def test_help_message(pytester: pytest.Pytester) -> None: """Make sure that the plugin is loaded by capturing an option it adds in the help message.""" @@ -28,8 +30,26 @@ def test_emptyconfig(pytester: pytest.Pytester) -> None: result.assert_outcomes() -def test_markers_are_registered(pytester: pytest.Pytester) -> None: - """Every marker the plugin applies must be registered, otherwise --strict-markers rejects it.""" +def test_resource_markers_are_registered(pytester: pytest.Pytester) -> None: + """The resource markers are built when the loader is imported, before a config exists. + + `--strict-markers` only validates a marker created once a config is attached, so it never sees + these. Compare them against the registered list instead. + """ + result = pytester.runpytest("--markers") + + registered = { + line.removeprefix("@pytest.mark.").split(":")[0].split("(")[0] + for line in result.stdout.lines + if line.startswith("@pytest.mark.") + } + missing = {mark.markname for mark in MARKER_MAPPING.values()} - registered + + assert not missing, f"markers applied by the loader but never registered: {sorted(missing)}" + + +def test_type_markers_are_registered(pytester: pytest.Pytester) -> None: + """The type markers are applied during collection, so --strict-markers rejects an unregistered one.""" pytester.makefile( ".yml", test_markers="""