-
-
Notifications
You must be signed in to change notification settings - Fork 354
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
Documentation on creating custom TestInfra Module #660
Comments
I also created a Reddit post asking for any pointers as well. |
Moin, I've been looking at this because I needed something similar. The main blocker for getting modules from other python modules loaded is in the testinfra.modules.get_modules method: pytest-testinfra/testinfra/modules/__init__.py Lines 48 to 52 in dc48cd9
This pretty much hardcodes all modules to live in python modules Changing this wouldn't be such a massive change. I've done so in a branch on a fork. I mostly split the builtin modules into a separate object and added a decorator to register modules, so external code only needs to care about the decorator: With this, I can setup a new module like this (just using firewalld as an example, as that's currently on my mind, and I haven't really implemented any proper parsing yet): from testinfra.modules.base import Module, register_module
@register_module("firewalld_zone")
class FirewalldZone(Module):
def __init__(self, zone):
self.zone = zone
super().__init__()
def info(self):
return self.check_output("firewall-cmd --info-zone {}".format(self.zone)) def test_foo(host):
zone = host.firewalld_zone("public")
... This should be fine from a security perspective, because I have to import the module anyhow to execute the module registration. I'm mostly concerned about introducing public APIs, but if the maintainers are fine with this, I could finish this up with some documentation and open a PR. Tests are running cleanly on the branch for me. |
I was looking for this feature. |
Details
I am wanting to write a custom TestInfra module for something that isn't provided by TestInfra by default. So, I wanted to test this out by doing something trivial. So, I looked at the testinfra/modules/podman.py file and thought I had identified how this should work, but I am not doing it correctly. Here is what my module is doing.
I then used Poetry to install the module. Then I use the following test file:
Then I ran the following command to attempt to run the module.
Then I got the following error.
Question
Is there any documentation on how to extend TestInfra with a custom module plugin? I'm not doing something correctly.
The text was updated successfully, but these errors were encountered: