Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: pytest plugin does not support the usage of relative imports #166

Closed
wvandeun opened this issue Dec 9, 2024 · 3 comments · Fixed by #171
Closed

bug: pytest plugin does not support the usage of relative imports #166

wvandeun opened this issue Dec 9, 2024 · 3 comments · Fixed by #171
Assignees
Labels
priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release type/bug Something isn't working as expected

Comments

@wvandeun
Copy link
Contributor

wvandeun commented Dec 9, 2024

Component

Python SDK

Infrahub SDK version

1.1.0

Current Behavior

You are unable to use the pytest plugin for user provided resources that use a relative import.

tests/test_resources.yml::infrahub_check__check_tag__smoke-test FAILED                                                 [100%]

========================================================== FAILURES ==========================================================
______________________________________ resource: infrahub_check__check_tag__smoke-test _______________________________________
attempted relative import with no known parent package
================================================== short test summary info ===================================================
FAILED tests/test_resources.yml::infrahub_check__check_tag__smoke-test
===================================================== 1 failed in 0.03s ======================================================

Expected Behavior

The pytest plugin works for user provided resources that use relative imports

Steps to Reproduce

  • spin up an instance of Infrahub
  • create a local repository and initialize it as a repository
  • create the file check_tag.py in the directory
from infrahub_sdk.checks import InfrahubCheck
from .utils import something

class MyCheck(InfrahubCheck):
    query = "check_tag"

    async def validate(self, data: dict) -> None:
        a = something()
        return
  • create the file utils.py in the directory
def something() -> str:
    return "something"
  • create the file check_tag.gql in the directory
query check_tag($name: String!) {
  BuiltinTag(name__value: $name) {
    edges {
      node {
	id
      }
    }
  }
}
  • create the file .infrahub.yml in the directory
---
check_definitions:
  - name: check_tag
    class_name: MyCheck
    file_path: "check_tag.py"
    targets: tags
    parameters:
      name: "name__value"
  • create a tests directory in the repository
  • create a file tests/test_resources.yml
---
version: "1.0"
infrahub_tests:
  - resource: Check
    resource_name: check_tag
    tests:
      - name: smoke-test
        expect: PASS
        spec:
          kind: check-smoke
  • in the root of the respository execute the following command
pytest -v

Additional Information

No response

@wvandeun wvandeun added the type/bug Something isn't working as expected label Dec 9, 2024
@ogenstad
Copy link
Contributor

As part of this we should move away from the get_check_class_instance() / get_transform_class_instance() functions and instead use the general .load_class() methods as defined within the repository schema. This work should be done after #160 has been merged to avoid extra conflicts.

@exalate-issue-sync exalate-issue-sync bot added the priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release label Dec 10, 2024
Copy link

[From petercrocker]

[~accountid:712020:ce1b5966-e028-4429-866c-40a86efdd75b] which issue to you mean by #160? Can’t find the right one, and this is a hot topic so want to see how to move it along

@ogenstad
Copy link
Contributor

It's this GitHub Pull request: https://github.com/opsmill/infrahub-sdk-python/pull/160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release type/bug Something isn't working as expected
Projects
None yet
2 participants