内置 fixtures 之 cache:
cache 是一个可以在测试会话之间保持状态的缓存对象;
源码展示:
@pytest.fixture
def cache(request):
"""
Return a cache object that can persist state between testing sessions.
cache.get(key, default)
cache.set(key, value)
Keys must be a ``/`` separated value, where the first part is usually the
name of your plugin or application to avoid clashes with other cache users.
Values can be any object handled by the json stdlib module.
"""
return request.config.cache
源码文档中已经说明,cache 提供了两个方法:
- cache.set(key, value):写入缓存;
- key 参数:缓存存储的路径,是相对于缓存文件 .pytest_cache/v/ 的相对路径,如无此路径会自动创建;
- value 参数:缓存的值;
- 注意:此方法写入缓存是实时写入的,测试未结束之前缓存文件未显示,但是缓存是已经被写入的;
- cache.get(key, default):返回给定键的缓存值,如果

最低0.47元/天 解锁文章
677

被折叠的 条评论
为什么被折叠?



