‹
测试
import pytest
def test_assert():
assert 2 > 1
assert 0.1 + 0.2 == pytest.approx(0.3)
# scope - function class module
@pytest.fixture(scope="function", autouse=False)
def db_conn():
conn = "模拟数据库连接"
yield conn
print("模拟关闭数据库连接")
# 将代码里面依赖的东西临时换掉, 隔离出特定测试环境, 提高测试速度和效率
def test_inner(monkeypatch):
"""内置"""
monkeypatch.setattr("module.target", "替换目标对象")