Django - 几乎所有测试都失败并出现相同的错误(NoReverseMatch)

时间:2017-09-23 05:52:58

标签: python django django-rest-framework django-testing

我曾经为django项目做出贡献,https://github.com/Cloud-CV/evalai以及过去常常工作的一切。在完成XUbuntu 16.04的全新安装后,我尝试再次配置项目。这次所有命令都运行正常,除非我运行测试套件。

python manage.py test --settings=settings.dev

在283项测试中,236项测试失败并出现类似的错误消息,但开发服务器工作正常。

这是失败的测试之一

def test_unstar_challenge(self):
    self.url = reverse_lazy('challenges:star_challenge',
                            kwargs={'challenge_pk': self.challenge.pk})
    self.star_challenge.is_starred = False
    expected = {
        'user': self.user.pk,
        'challenge': self.challenge.pk,
        'count': 0,
        'is_starred': self.star_challenge.is_starred,
    }
    response = self.client.post(self.url, {})
    self.assertEqual(response.data, expected)
    self.assertEqual(response.status_code, status.HTTP_200_OK)

这是它的错误信息。

.
.
.
.
======================================================================
ERROR: test_particular_challenge_update_with_no_data (tests.unit.challenges.test_views.UpdateParticularChallengePhase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jeff/evalai/tests/unit/challenges/test_views.py", line 1320, in test_particular_challenge_update_with_no_data
    response = self.client.put(self.url, self.data)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/rest_framework/test.py", line 298, in put
    path, data=data, format=format, content_type=content_type, **extra)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/rest_framework/test.py", line 216, in put
    return self.generic('PUT', path, data, content_type, **extra)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/django/test/client.py", line 409, in generic
    return self.request(**r)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/rest_framework/test.py", line 279, in request
    return super(APIClient, self).request(**kwargs)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/rest_framework/test.py", line 231, in request
    request = super(APIRequestFactory, self).request(**kwargs)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/django/test/client.py", line 476, in request
    response = self.handler(environ)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/django/test/client.py", line 129, in __call__
    self.load_middleware()
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 80, in load_middleware
    middleware = import_string(middleware_path)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/silk/middleware.py", line 39, in <module>
    fpath = silky_reverse('summary')
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/silk/middleware.py", line 35, in silky_reverse
    r = reverse(name, *args, **kwargs)
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/django/urls/base.py", line 91, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
  File "/home/jeff/evalai/venv/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 392, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns)
NoReverseMatch: Reverse for 'summary' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

----------------------------------------------------------------------
Ran 283 tests in 6.057s

FAILED (errors=236)
Destroying test database for alias 'default'...

我研究了很多,但它似乎只是我面临的一个问题。任何帮助表示赞赏。 :)

1 个答案:

答案 0 :(得分:0)

确保您的设置配置正确。如果settings.DEBUGTrue,则您项目的urls.py文件仅包含真丝网址。

如果它适用于其他所有人,那么您最有可能的解决方案就像设置一样小。