[英]Register method to run at tearDown in python unittest using pytest?
类似的问题,但对于单元测试是讨论在这里
我知道 pytest 与 unittest 兼容。
我不知道什么是内置在pytest又名纯pytest方式注册一个试运行的上exitting事件?
ps
我在谷歌和我们的 stackoverflow 上的搜索没有帮助
一种方法是使用会话范围的固定装置,它在启动时产生,然后在产生后执行拆卸操作。 一个玩具演示:
import pytest
@pytest.fixture(scope = 'session')
def db():
yield 'DbConnection()'
# Occurs after all tests run.
print('TEARING DOWN')
def test_foo(db):
print(db, id(db))
def test_bar(db):
print(db, id(db))
输出:
pytest-teardown.py DbConnection() 4489248432
.DbConnection() 4489248432
.TEARING DOWN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.