我是pytest的新手并试图使用fixture。
我有以下代码:
我正在尝试将以下逻辑转换为fixture:
我有一个名为“kubernetes_.fixture”的函数,它是一个夹具
给我一个功能夹具。然后我列出这些并将其发送给其他函数。
但是,当我在一个fixture函数中将逻辑更改为2逻辑时 我收到以下错误。
pod2 = (kubernetes_.fixture([samelink_pod2], namespace='namespace'))
pod3 = (kubernetes_.fixture([difflink_pod3], namespace='namespace'))
pod4 = (kubernetes_.fixture([diff_leaf_pod4], namespace='namespace'))
pod5 = (kubernetes_.fixture([diff_leaf_pod5], namespace='namespace'))
@pytest.fixture
def pod_list_fixture(pod2, pod3, pod4, pod5):
return [pod2, pod3, pod4, pod5]
def test_same_node_traffic(pod_list_fixture):
connected_ips = [pod.ip() for pod in pod_list_fixture]<<<< Never get ERRROR HERE
________________________________________________________________
@pytest.fixture
def pod_list_fixture():
fixlist = []
for pod in podlist:
fixture = (kubernetes_.fixture([pod], namespace='namespace'))
fixlist.append(fixture)
return fixlist
def test_same_node_traffic(pod_list_fixture):
connected_ips = [pod.ip() for pod in pod_list_fixture] <<< Get a Error here saying function object doesnt have attribute 'ip'
TRACEBACK:
pod_list_fixture = [<function fixture.<locals>._fixture at 0x7f9678734268>, <function fixture.<locals>._fixture at 0x7f96787348c8>, <func...>, <function fixture.<locals>._fixture at 0x7f9678734840>, <function fixture.<locals>._fixture at 0x7f9678734d08>, ...]
def test_different_uplink(pod_list_fixture):
> connected_ips = [pod.ip() for pod in pod_list_fixture]
test_remote.py:58:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <list_iterator object at 0x7f965865c860>
> connected_ips = [pod.ip() for pod in pod_list_fixture]
E AttributeError: 'function' object has no attribute 'ip'
test_remote.py:58: AttributeError
__________________________ test_different_leaf[kubernetes-1.8] ___________________________
pod_list_fixture = [<function fixture.<locals>._fixture at 0x7f9678734268>, <function fixture.<locals>._fixture at 0x7f96787348c8>, <func...>, <function fixture.<locals>._fixture at 0x7f9678734840>, <function fixture.<locals>._fixture at 0x7f9678734d08>, ...]
def test_different_leaf(pod_list_fixture):
> connected_ips = [pod.ip() for pod in pod_list_fixture]
test_remote.py:64:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <list_iterator object at 0x7f9658649f60>
> connected_ips = [pod.ip() for pod in pod_list_fixture]
E AttributeError: 'function' object has no attribute 'ip'
test_remote.py:64: AttributeError