0

ansible transport で testinfra を使用しています。hostを備えたフィクスチャを提供するansibleので、できますhost.ansible.get_variables()

次に、このインベントリの値に基づいてテストのパラメーター化を作成する必要があります。

在庫:

foo:
  hosts:
    foo1:
      somedata:
        - data1
        - data2

インベントリ内の各ホストの somedata からの「データ」をそれぞれテストするテストを作成したいと考えています。「各ホスト」の部分は testnfra によって処理されますが、テストのパラメーター化に苦労しています。

@pytest.fixture
def somedata(host):
    return host.ansible.get_variables()["somedata"]

@pytest.fixture(params=somedata):
def data(request):
    return request.param


def test_data(host, data):
   assert 'data' in data

私は両方の方法を試しました:

  • @pytest.fixture(params=somedata)->TypeError: 'function' object is not iterable
  • @pytest.fixture(params=somedata())->Fixture "somedata" called directly. Fixtures are not meant to be called directly...

これどうやってするの?テスト時にテストの数を変更できないことは理解していますが、収集時に同じインベントリを持っていると確信しているので、理論的には実行可能です...

4

2 に答える 2