title: Using an array of testinfra_hosts, can you control the parametrized values used for each host in a test?
body: <p>I'm trying to write a test suite for verifying the state of some servers using testinfra.</p>
  <p>It's my first time working with python/testinfra/pytest.</p>
  <p>As a brief pseudocodey example</p>
  <p>test_files.py</p>
  <pre><code>testinfra_hosts=[server1,server2,server3] 
  
  with open(&quot;tests/microservices_default_params.yml&quot;, &quot;r&quot;) as f:
      try:
          default_params = yaml.safe_load(f)
      except yaml.YAMLError as exc:
          print(exc)
  
  with open(&quot;tests/&quot; + server + &quot;/params/&quot; + server + &quot;_params.yml&quot;, &quot;r&quot;) as f:
      try:
          instance_params = yaml.safe_load(f)
      except yaml.YAMLError as exc:
          print(exc)
  
  @pytest.mark.parametrize(
      &quot;name&quot;, [] + default_params[&quot;files&quot;] + instance_params[&quot;files&quot;]
  )
  
  def test_files(host, name):
      file = host.file(name)
      assert file.exists
  </code></pre>
  <p>Each server has it's own unique params yaml file.
  I want every server to go through the same test, however I need each server to run the test with its own parametrized values from its respective .yml file.</p>
  <p>The problem with the code above, is that it will try to execute all of server1s unique params against both server 2 and 3, then will start again with server 2 being run against servers 1-3 unique params.</p>
  <p>I can't find a clean way to essentially have the test run once with server1 as the host, and server 1 params, then do the same again with server2 and server2 params etc.</p>
  <p>I've tried using for loops within the test file itself, reading each instance_params.yml into a dictionary with the key being the server name and value containing all of that servers params - but that doesn't smell very good and because the assert is inside the loop, if one of the params for that server fails the loop exits and doesn't attempt any further params for that server.</p>
  <p>I've looked into pytest_collection_modifyitems but I can't quite get my head around how to let it do what I want. I feel like there may be an easy solution to this that I'm missing.</p>
  <p>My last resort would be to seperate out the tests and parametrized params individually as</p>
  <pre><code>@pytest.mark.parametrize(
   &quot;server1_params&quot;, instance_params['server1']['files]
  )
  def_test_files_server1(host, server1_params):
  ...
  @pytest.mark.parametrize(
   &quot;server2_params&quot;, instance_params['server2']['files]
  )
  def_test_files_server2(host,server2_params):
  ...
  </code></pre>
  <p>That approach doesn't sound right to me though.</p>
  <p>Any help for a fresh junior would be appreciated, I've never asked anything here before
  Hope it makes sense :)</p>
  <p>Update:
  @ajk Found the solution!
  The pytest_generate_tests function was exactly what I was needing - and I've furthered my understanding of pytest along the way.</p>
  <p>Thanks ajk! I owe you one :D</p>