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..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,6 +30,72 @@ def test_emptyconfig(pytester: pytest.Pytester) -> None: result.assert_outcomes() +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=""" + --- + 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(