Skip to content

Commit c463cce

Browse files
committed
Fix pytest plugin relative import
1 parent fc61aff commit c463cce

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

infrahub_sdk/checks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ def get_check_class_instance(
189189
try:
190190
spec = importlib.util.spec_from_file_location(check_config.class_name, search_location)
191191
module = importlib.util.module_from_spec(spec) # type: ignore[arg-type]
192+
193+
# Set base module for relative import. This is useful when pytest plugin runs through proposed change pipeline,
194+
# as pytest is invoked outside of the imported repository.
195+
module.__package__ = str(search_location.parent)
196+
192197
spec.loader.exec_module(module) # type: ignore[union-attr]
193198

194199
# Get the specified class from the module

0 commit comments

Comments
 (0)