Skip to content

Commit 2c4e1b1

Browse files
committed
Change pytest plugin to use the same importer as other components
Fixes #166
1 parent 4df0d61 commit 2c4e1b1

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

changelog/166.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix relative imports for the pytest plugin, note that the relative imports can't be at the top level of the repository alongside .infrahub.yml. They have to be located within a subfolder.

infrahub_sdk/pytest_plugin/items/check.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

33
import asyncio
4+
from pathlib import Path
45
from typing import TYPE_CHECKING, Any, Optional
56

67
import ujson
78
from httpx import HTTPStatusError
89

9-
from ...checks import get_check_class_instance
1010
from ..exceptions import CheckDefinitionError, CheckResultError
1111
from ..models import InfrahubTestExpectedResult
1212
from .base import InfrahubItem
@@ -33,10 +33,10 @@ def __init__(
3333
self.check_instance: InfrahubCheck
3434

3535
def instantiate_check(self) -> None:
36-
self.check_instance = get_check_class_instance(
37-
check_config=self.resource_config, # type: ignore[arg-type]
38-
search_path=self.session.infrahub_config_path.parent, # type: ignore[attr-defined]
36+
relative_path = (
37+
str(self.resource_config.file_path.parent) if self.resource_config.file_path.parent != Path() else None # type: ignore[attr-defined]
3938
)
39+
self.check_instance = self.resource_config.load_class(import_root=str(Path.cwd()), relative_path=relative_path) # type: ignore[attr-defined]
4040

4141
def run_check(self, variables: dict[str, Any]) -> Any:
4242
self.instantiate_check()

infrahub_sdk/pytest_plugin/items/python_transform.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

33
import asyncio
4+
from pathlib import Path
45
from typing import TYPE_CHECKING, Any, Optional
56

67
import ujson
78
from httpx import HTTPStatusError
89

9-
from ...transforms import get_transform_class_instance
1010
from ..exceptions import OutputMatchError, PythonTransformDefinitionError
1111
from ..models import InfrahubTestExpectedResult
1212
from .base import InfrahubItem
@@ -33,9 +33,11 @@ def __init__(
3333
self.transform_instance: InfrahubTransform
3434

3535
def instantiate_transform(self) -> None:
36-
self.transform_instance = get_transform_class_instance(
37-
transform_config=self.resource_config, # type: ignore[arg-type]
38-
search_path=self.session.infrahub_config_path.parent, # type: ignore[attr-defined]
36+
relative_path = (
37+
str(self.resource_config.file_path.parent) if self.resource_config.file_path.parent != Path() else None # type: ignore[attr-defined]
38+
)
39+
self.transform_instance = self.resource_config.load_class( # type: ignore[attr-defined]
40+
import_root=str(Path.cwd()), relative_path=relative_path
3941
)
4042

4143
def run_transform(self, variables: dict[str, Any]) -> Any:

0 commit comments

Comments
 (0)