小编Gui*_*lva的帖子

带有异步测试的 Pytest:之前和之后的测试设置

我使用 pytest 夹具的测试设置配置有问题:

@pytest.fixture(autouse=True)
async def run_around_tests(elastic_api, catalog):
    es_index_mapping = open('test/resources/es_index_mapping.json')
    es_index_mapping_dict = json.load(es_index_mapping)
    es_cars = open('test/resources/es_cars.json')
    es_cars_dict = json.load(es_cars)
    await elastic_api.create_index(index='catalog_test', payload=es_index_mapping_dict)
    await catalog.upsert_documents(index='catalog_test', payload=es_cars_dict)
    yield
    await elastic_api.delete_index(index='catalog_test')
    await catalog.close()
Run Code Online (Sandbox Code Playgroud)

似乎yield 没有正确执行并且没有等待测试执行。在测试执行期间发生elasticsearch索引的删除,导致测试失败。为什么只有在所有测试完成后才执行此删除?

python pytest python-asyncio

3
推荐指数
1
解决办法
3869
查看次数

标签 统计

pytest ×1

python ×1

python-asyncio ×1