Skip to content

Commit a2a28e0

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

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

infrahub_sdk/checks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ 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+
# Note that using __package__ logs a `DeprecationWarning: __package__ != __spec__.parent`
196+
module.__package__ = str(search_location.parent.name)
197+
192198
spec.loader.exec_module(module) # type: ignore[union-attr]
193199

194200
# Get the specified class from the module

0 commit comments

Comments
 (0)