【发布时间】:2021-05-27 14:21:49
【问题描述】:
我需要删除一些为测试而创建的文件夹。
在主测试文件夹中,我创建了一个文件test_teardown.py,内容如下。
import shutil
import pytest
@pytest.fixture(scope="session")
def teardown():
yield
shutil.rmtree('tmp')
不过,tmp 文件夹在测试会话完成后并没有被删除。我是不是用错了灯具?
文件结构
+-- Project folder
| +-- tests
| | +-- __init__.py
| | +-- test_teardown.py
| | +-- Unit
| | | +-- __init__.py
| | | +-- test_moretests.py
【问题讨论】:
-
如果要自动参与,需要将fixture设置为
autouse=True。 -
非常感谢,完美运行!