Python Get和Post请求在unittests中不起作用
我在为我的API路由编写测试时遇到问题。我可以通过邮递员或浏览器获取和发布数据,但当我发布测试环境中的GET请求时,它总是返回404响应。我尝试了不同的路线,但都不管用。我做错了什么 base.py:Python Get和Post请求在unittests中不起作用,python,flask,python-unittest,Python,Flask,Python Unittest,我在为我的API路由编写测试时遇到问题。我可以通过邮递员或浏览器获取和发布数据,但当我发布测试环境中的GET请求时,它总是返回404响应。我尝试了不同的路线,但都不管用。我做错了什么 base.py: class BaseTestCase(unittest.TestCase): def __init__(self, *args, **kwargs): self.app = create_app() self.app_con
class BaseTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
self.app = create_app()
self.app_context = self.app.app_context()
self.app_context.push()
super(BaseTestCase, self).__init__(*args, **kwargs)
def create_app(self):
self.app.config.from_object("project.config.TestingConfig")
return self.app
def setUp(self):
db.create_all()
db.session.commit()
test_users.py:
class TestUsers(BaseTestCase):
""" Test Users service"""
def __init__(self, *args, **kwargs):
self.app = create_app()
self.app_test = self.app.test_client()
super(TestUsers, self).__init__(*args, **kwargs)
def test_add_user(self):
with self.app.test_client() as client:
res = client.get('/register')
print(res.status_code)
self.assertEqual(res.status_code, 200)
测试失败:
self.assertEqual(res.status_code, 200)
AssertionError: 404 != 200