在我的app.py
我有以下代码:
from sanic import Sanic
my_dep = load_production_dep()
app = Sanic()
@app.route("/")
def hello(request):
return my_dep.hello()
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)
如何将其my_dep
注入我的 sanic 应用程序实例?使用上面的当前设置,我无法完全测试我的代码,因为我的路由依赖于模块中加载的全局依赖项。
换句话说:我如何重组这个简单的应用程序,使其易于测试?