当试图在PyCharm的Django django-nose下使用coverage进行测试时,我可以't seem to get the coverage report to work. I'尝试使用捆绑的 coverage.py
而不使用 . 没有捆绑 coverage.py
我看到:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/coverage_runner/run_coverage.py", line 44, in <module>
main()
File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/cmdline.py", line 741, in main
status = CoverageScript().command_line(argv)
File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/cmdline.py", line 481, in command_line
return self.do_run(options, args)
File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/cmdline.py", line 625, in do_run
self.coverage.stop()
File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/control.py", line 692, in stop
self.collector.stop()
File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/collector.py", line 277, in stop
"Expected current collector to be %r, but it's %r" % (self, self._collectors[-1])
AssertionError: Expected current collector to be <Collector at 0x10e0cfbe0: CTracer>, but it's <Collector at 0x10fa368d0: CTracer>
有了它,我看到:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/coverage_runner/run_coverage.py", line 44, in <module>
main()
File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/cmdline.py", line 721, in main
status = CoverageScript().command_line(argv)
File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/cmdline.py", line 438, in command_line
self.do_execute(options, args)
File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/cmdline.py", line 580, in do_execute
self.coverage.stop()
File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/control.py", line 410, in stop
self.collector.stop()
File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/collector.py", line 294, in stop
assert self._collectors[-1] is self
AssertionError
我的测试和覆盖率报告通过命令行正常工作,即:
$ python manage.py test
我已经使用Django测试模板设置了一个运行配置,据我所知,我没有做任何特殊或异常的事情 . 有没有人碰到这个并解决了它?覆盖整合非常有用!
更新
此问题已在JetBrains here中打开 .
1 回答
我假设你的配置中有类似的东西:
PyCharm的覆盖范围在配置时会爆炸 . 我假设它要么运行两个覆盖实例,要么覆盖输出不是预期要解析的 . 无论哪种方式,似乎你现在都不能使用它 .
Solutions for now:
删除
NOSE_ARGS
config,如果您的任何自动/持续集成工具需要它,请使用命令行上的coverage选项运行它们:python manage.py test --with-coverage --cover-package=foo
(我选择此选项是因为PyCharm的好处)不要在PyCharm中使用coverage
注意:我能找到有这个问题的其他人here .