【发布时间】:2019-11-18 07:15:20
【问题描述】:
我有一个夹具,它返回端点名称(传入)
名称是测试中设置的字符串。我在测试(参数化)中每次调用端点都搞砸了,现在我无法弄清楚如何在不每次调用端点的情况下获得相同的功能。
基本上,我只需要调用一次端点,然后在该文件中的所有测试之间传递该数据(理想情况下,无需创建类并在测试中调用它。我有大约 12 个文件,每个文件都有类似的测试,我想要减少样板。理想情况下,如果它可以在没有全局变量的夹具/参数化级别完成。
这是我目前所拥有的:
@pytest.mark.parametrize('field', [('beskrivelse'), ('systemId')])
def test_intgra_001_elevforhold_req_fields(return_endpoint, field):
ep_to_get = 'get_elevforhold'
ep_returned = return_endpoint(ep_to_get)
apiv2 = Apiv2()
apiv2.entity_check(ep_returned, field, ep_to_get, False)
@pytest.fixture()
def return_endpoint():
def endpoint_initialisation(ep_name):
apiv2 = Apiv2()
ep_data = apiv2.get_ep_name(ep_name)
response = apiv2.get_endpoint_local(ep_data, 200)
content = json.loads(response.content)
apiv2.content_filt(content)
apiv2_data = content['data']
return apiv2_data
return endpoint_initialisation
【问题讨论】: