我正在开发一个 django API。现在我在端点上做一些测试,当我执行'python manage.py test'时一切顺利。但是当我使用标志'--with-coverage'或'coverage run --source='。manage.py 测试应用程序 && 覆盖率报告”我收到错误“KeyError:“BREAK_LOOP”。有人可以帮助我吗?
代码
from django.test import TestCase
import requests
class Teste(TestCase):
url = "localhost://endpoint/"
def test(self):
token = self.token
headers={
'content-type' : 'application/json',
'Authorization' : token
}
response = requests.get(self.url, headers=headers)
self.assertEqual(response.status_code, 403)
错误
nosetests --with-coverage --verbosity=1
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv
super().run_from_argv(argv)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/django/core/management/commands/test.py", line 53, in handle
failures = test_runner.run_tests(test_labels)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/django_nose/runner.py", line 308, in run_tests
result = self.run_suite(nose_argv)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/django_nose/runner.py", line 244, in run_suite
nose.core.TestProgram(argv=nose_argv, exit=False,
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/nose/core.py", line 118, in __init__
unittest.TestProgram.__init__(
File "/usr/lib/python3.8/unittest/main.py", line 100, in __init__
self.parseArgs(argv)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/nose/core.py", line 145, in parseArgs
self.config.configure(argv, doc=self.usage())
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/nose/config.py", line 346, in configure
self.plugins.configure(options, self)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/nose/plugins/manager.py", line 284, in configure
cfg(options, config)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/nose/plugins/manager.py", line 99, in __call__
return self.call(*arg, **kw)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/nose/plugins/manager.py", line 167, in simple
result = meth(*arg, **kw)
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/nose/plugins/cover.py", line 104, in configure
import coverage
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/coverage/__init__.py", line 10, in <module>
from coverage.control import coverage, process_startup
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/coverage/control.py", line 13, in <module>
from coverage.html import HtmlReporter
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/coverage/html.py", line 10, in <module>
from coverage.results import Numbers
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/coverage/results.py", line 7, in <module>
from coverage.parser import CodeParser
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/coverage/parser.py", line 315, in <module>
OP_BREAK_LOOP = _opcode('BREAK_LOOP')
File "/home/user/.virtualenvs/env/lib/python3.8/site-packages/coverage/parser.py", line 274, in _opcode
return opcode.opmap[name]
KeyError: 'BREAK_LOOP'