假设我有一个这样的课程.
class SomeProductionProcess(CustomCachedSingleTon):
def loaddata():
"""
Uses an iterator over a large file in Production for the Data pipeline.
"""
pass
Run Code Online (Sandbox Code Playgroud)
现在在测试时我想改变loaddata()方法内部的逻辑.这将是一个简单的自定义逻辑,不处理大数据.
我们如何loaddata()使用Python Mock UnitTest框架在测试时提供自定义实现?
是否可以autouse=True仅使用特定标记来阻止"功能范围"灯具的执行?
我将以下fixture设置为autouse,以便自动模拟所有传出请求:
@pytest.fixture(autouse=True)
def no_requests(monkeypatch):
monkeypatch.setattr("requests.sessions.Session.request", MagicMock())
Run Code Online (Sandbox Code Playgroud)
但我有一个标记叫做endtoend我用来定义一系列测试,允许外部请求进行更强大的端到端测试.我想注入no_requests所有测试(绝大多数),但不是在以下测试中:
@pytest.mark.endtoend
def test_api_returns_ok():
assert make_request().status_code == 200
Run Code Online (Sandbox Code Playgroud)
这可能吗?