python - 如何手动触发共享 pytest fixture 的重新执行?

标签 python unit-testing pytest

假设我有一个装置,我想在大部分测试中分享它:

@pytest.fixture(scope='session')
def account():
   # create a new account

但现在在其中一项测试中,我想覆盖 scope='session' 位并实际重新执行固定装置(创建一个新帐户)。有没有一种方法可以告诉固定装置“覆盖缓存/内存”仅用于一次测试?

最佳答案

只需从测试中手动调用 fixture 将导致其重新执行。例如

def test_foo():
    new_account = account()

关于python - 如何手动触发共享 pytest fixture 的重新执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35257195/

相关文章:

python - 离散优化(SOS1 约束)- GEKKO

c# - EntityFramework 核心测试内存数据库错误

python - 避免打印点

python - py.test teardown 查看测试是否失败并打印子进程输出

Python:初始化空嵌套列表时的奇怪列表行为

python - Django 测试用例 : recreate database in self. 子测试(...)

java - Java 中的随机测试 - 它是什么以及如何实现它?

python - 如何在单个 html 文件中获取 django 覆盖率报告

postgresql - py.test 混合装置和 asyncio 协程

python - 从c更新python变量