【发布时间】:2017-07-27 21:26:11
【问题描述】:
在使用py.test 运行测试时,我使用joblib.Memory 来缓存昂贵的计算。我正在使用的代码简化为以下内容,
from joblib import Memory
memory = Memory(cachedir='/tmp/')
@memory.cache
def expensive_function(x):
return x**2 # some computationally expensive operation here
def test_other_function():
input_ds = expensive_function(x=10)
## run some tests with input_ds
效果很好。我知道使用tmpdir_factory 固定装置可能会更优雅地完成此操作,但这不是重点。
我遇到的问题是如何在所有测试运行后清理缓存的文件,
- 是否可以在所有测试之间共享一个全局变量(例如包含缓存对象的路径列表)?
- py.test 中是否有一种机制可以在所有测试运行后调用某些命令(无论它们是否成功)?
【问题讨论】: