【发布时间】:2020-12-27 20:08:58
【问题描述】:
我正在尝试在金字塔中测试使用request.current_route_path() 的视图。
我将使用基本的测试设置,几乎直接来自文档:
from ..views.auth import signup
...
class ....:
def test_signup_view(self):
with testing.testConfig():
signup(testing.DummyRequest(self.session))
我正在使用类似于https://docs.pylonsproject.org/projects/pyramid/en/latest/tutorials/wiki2/tests.html的配置:
class BaseTest(unittest.TestCase):
def setUp(self) -> None:
self.config = testing.setUp(settings={
'sqlalchemy.url': self.postgresql.url().replace("postgresql", "postgresql+pg8000", 1)
})
self.config.include('..models')
self.config.include('..routes')
...
但这会导致ValueError: Current request matches no route
我将path="/signup" 参数添加到DummyRequest,但最终出现相同的错误。
我的路由是基于uris的,不是基于资源的,所以测试的具体路由是:
def includeme(config):
...
config.add_route('signup', '/signup')
...
我该如何解决这个问题?
【问题讨论】:
-
您参考了哪些文档?请提供链接。
-
另外,请在
testing.testConfig中包含您的路线配置以及加载方式。 -
@StevePiercy 我关注docs.pylonsproject.org/projects/pyramid/en/latest/tutorials/…