Send generated values in test as parameters to fixture in pytest

。
订阅者
271
文章
0
粉丝
测试交流评论140字数 254阅读0分50秒阅读模式
摘要Let me give you and idea of what the test is about. In this test, I'm calling an API that ...

Let me give you and idea of what the test is about.
In this test, I'm calling an API that basically generates a file and an item in a DynamoDB table. The response the service, gives me the UUID that I use to look into the DB and check that everything is created correctly.
However, I cannot do the teardown in fixture because the uuid I need to delete item in dynamo is generated in the test. Right now, I'm deleting the item in the test but I wanted to do it in the fixture but I'm not sure if its possible to pass this uuid to the fixture.
Any suggestions or ideas?

@pytest.fixture
def prepare_test(self):
    body = open(self._filepath, "r")
    yield body
def test_post_template_tyc_happy_path(self, prepare_test):
    body = prepare_test
    response_body = self._tyc_api.post_template_contract(body.read(), header, 'LOAN', 'GOBIERNO', 'AUTOMATED_QA_TEST')
    result_dynamo = self._tyc_crud.find_contract_by_product_id_and_tac_version_id_async(response_body['productId'], response_body['tacVersionId'])
    assert response_body['productId'] == 'LOAN'
    assert response_body['tacVersionId'][:-36] == 'GOBIERNO#'
    assert response_body['description'] == 'AUTOMATED_QA_TEST'
    assert response_body['isLastVersion'] is True
    assert result_dynamo.description == 'AUTOMATED_QA_TEST'
    assert result_dynamo.tac_id == 'GOBIERNO'
    self.delete_test_data(response_body['productId'], response_body['tacVersionId'])
def delete_test_data(self, product_id, tac_version_id):
    self._tyc_crud.delete_contract_by_product_id_and_tac_version_id(product_id, tac_version_id)

Thanks!文章源自玩技e族-https://www.playezu.com/179287.html 文章源自玩技e族-https://www.playezu.com/179287.html

 
匿名

发表评论

匿名网友
确定

拖动滑块以完成验证