在运行python manage.py测试时出现此错误,请帮助我解决此问题
ERROR: test_update_status_table_using_message_table_func (update_status.tests.Up
date_Status_Test)
Traceback (most recent call last):
File "C:\Users\USER\syuvira\update_status\tests.py", line 67, in test_update_s
tatus_table_using_message_table_func
found = resolve('/update-status/show_post')
File "C:\Users\USER\env\lib\site-packages\django\urls\base.py", line 27, in re
solve
return get_resolver(urlconf).resolve(path)
File "C:\Users\USER\env\lib\site-packages\django\urls\resolvers.py", line 392,
in resolve
raise Resolver404({'tried': tried, 'path': new_path})
django.urls.exceptions.Resolver404: {'tried': [[<RegexURLResolver <RegexURLPatte
rn list> (admin:admin) ^admin/>], [<RegexURLResolver <module 'profile_page.urls'
from 'C:\\Users\\USER\\syuvira\\profile_page\\urls.py'> (None:profile-page) ^pr
ofile-page/>], [<RegexURLResolver <module 'Add_Friend.urls' from 'C:\\Users\\USE
R\\syuvira\\Add_Friend\\urls.py'> (None:Add-Friend) ^Add-Friend/>], [<RegexURLRe
solver <module 'dashboard.urls' from 'C:\\Users\\USER\\syuvira\\dashboard\\urls.
py'> (None:dashboard) ^dashboard/>], [<RegexURLResolver <module 'welcome_page.ur
ls' from 'C:\\Users\\USER\\syuvira\\welcome_page\\urls.py'> (None:welcome-page)
^welcome-page/>], [<RegexURLPattern index ^$>]], 'path': 'update-status/show_pos
t'}这是我的tests.py
def test_update_status_using_index_func(self):
found = resolve('/update-status/')
self.assertEqual(found.func, index)发布于 2017-11-06 11:23:37
在您的测试代码中触发的Handle the exception resolve函数。
如果URL不能解析,该函数将引发Resolver404异常(Http404的子类)。
def test_update_status_using_index_func(self):
try:
found = resolve('/update-status/')
self.assertEqual(found.func, index)
except Resolver404:
self.fail("Couldn't not resolve URL')发布于 2020-04-09 01:49:46
另一种测试方法是:
from django.test import Client, TestCase
from django.urls import resolve, Resolver404
from myproject import settings
class TestError404(TestCase):
def setUp(self):
self.client = Client()
self.debug = settings.DEBUG
settings.DEBUG = False
def tearDown(self):
settings.DEBUG = self.debug
def test_404(self):
with self.assertRaises(Resolver404):
resolve('/foo/')https://stackoverflow.com/questions/47129236
复制相似问题