我将用 Pytest 模拟一个认证装饰器。框架是 Pylons。 如果您有任何经验,可以告诉我吗? 请帮我!这对我很重要。
api.py
@validate_and_configure_for_network
def ping(self):
data = {
"status": 200,
"message": "OK"
}
return self.json_response(http_status=200, full_response=data)
conftest.py
@pytest.fixture
def app(mocker):
mocker.patch("ss.core.util.apiutil.validate_and_configure_for_network", return_value=True)
app = create_app()
return app
test_api.py
class TestPing():
def test_ping(self):
var = NewApiController()
...