【问题标题】:How to make sure the fixture executes after all tests have executed?在所有测试执行后如何确保夹具执行?
【发布时间】:2021-11-14 22:16:13
【问题描述】:

我创建了几个测试,它们在测试文件夹中创建不同的文件和文件夹。我想删除通过测试创建的所有文件夹,但仅在测试执行结束时。我已经写了这个夹具:

import shutil

@fixture(scope='session',autouse=True)
def delete_files():
    yield None
    shutil.rmtree('test-folder')

但不知何故,这不会在所有测试都通过后最后执行。如何解决这个问题并在测试执行结束时删除所有测试文件夹?

【问题讨论】:

标签: python directory pytest fixtures


【解决方案1】:

对于另一种方法,我以前使用过tmp_path 目录,请参阅here 示例用例和here 以获取该夹具的文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 2020-05-23
    • 2021-09-11
    • 1970-01-01
    相关资源
    最近更新 更多