Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1231.fixed.md
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 1 addition & 1 deletion infrahub_sdk/pytest_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
68 changes: 68 additions & 0 deletions tests/unit/pytest_plugin/test_plugin.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down Expand Up @@ -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(
Expand Down