0

i'm working on a script test with testinfra plugin to check and validate any servers deployment. testinfra plugin has a fixture "host" which is used to connect to the server. we can use it with the argument "pytest --hosts=". The idea here i need to create some others fixture to get data from my configuration management. I would like to re-use the argument "hosts" from testinfra plugin with my external function. Like that, i should be able to call my function into a fixture and use this fixture with pytest.mark.parametrize

im not a developper and its my first time using pytest/testinfra so i dont even know if its possible.

NicoW
  • 61
  • 5
  • I'm really not clear about your wants or needs, but from the testinfra readme it looks like `host` is exposed as a regular fixture, so you can just take it as parameter in any other fixture and use it however you want. – Masklinn Aug 28 '23 at 09:10
  • Hello, yeah it may be not really clear. To be more specific: In my repo i have a file.py which define a class which take a name server as argument (the fqdn). In this class i have several method to retrieve information from my configuration management. And from the values returned by those methods i created different fixture. i would like to know, if its possible to get the fqdn from --hosts testinfra to be use as the fqdn argument to define my "regular" class. – NicoW Aug 28 '23 at 09:35
  • 1
    If I understand your setup correctly, it reads like you can define a fixture which depends on `host` and instantiates and returns the utility class. Subsequent fixtures can then depend on *that* fixture, and get what data they need from the utility instance it returns. This is fairly routine, most of pytest's builtin fixtures return a "smart" object of some sort. – Masklinn Aug 28 '23 at 10:00
  • hi, okay thanks for the answer ! By any chances, do you have any examples ? and/or a ressource which explain this routine ? EDIT: i think this post may answser to my question https://stackoverflow.com/questions/76441415/passing-functions-as-a-parameter-in-pytest – NicoW Aug 28 '23 at 12:08

0 Answers0