6

我对 python 测试相当熟悉,所以这可能是我做错了..

当我运行我的测试时,测试运行器工作正常并且覆盖范围也......但在两者之间我得到一个断言错误:

Traceback (most recent call last):
  File "/usr/local/bin/coverage", line 9, in <module>
    load_entry_point('coverage==3.5.1', 'console_scripts', 'coverage')()
  File "/usr/local/lib/python2.7/dist-packages/coverage/cmdline.py", line 657, in main
    status = CoverageScript().command_line(argv)
  File "/usr/local/lib/python2.7/dist-packages/coverage/cmdline.py", line 526, in command_line
    self.coverage.stop()
  File "/usr/local/lib/python2.7/dist-packages/coverage/control.py", line 389, in stop
    self.collector.stop()
  File "/usr/local/lib/python2.7/dist-packages/coverage/collector.py", line 262, in stop
    assert self._collectors[-1] is self
AssertionError

为了让事情变得更加困难,我正在尝试测试一个命令行实用程序。这意味着我必须告诉覆盖范围以覆盖子流程调用。

我想我让这部分工作了,因为覆盖率现在报告正在运行的脚本的覆盖率百分比。但是由于我得到了覆盖工作,所以我无法摆脱 AssertionError。

一些帮助理解出了什么问题将不胜感激。我所有的代码都可以在 github 上找到:

快速运行:

cd /tmp/ && git clone git://github.com/h3/django-duke-client.git 
cd django-duke-client && chmod a+x run_tests && ./run_tests

谢谢

更新

我在另一台计算机上运行了测试,得到了相同的 AssertionError .. 加上一个新的 TypeError。测试再次正确运行,即使出现这些错误,覆盖率似乎也能正常工作。

...
Ran 9 tests in 1.324s

OK
Traceback (most recent call last):
  File "/usr/local/bin/coverage", line 9, in <module>
    load_entry_point('coverage==3.5.1', 'console_scripts', 'coverage')()
  File "/usr/local/lib/python2.7/dist-packages/coverage/cmdline.py", line 657, in main
    status = CoverageScript().command_line(argv)
  File "/usr/local/lib/python2.7/dist-packages/coverage/cmdline.py", line 526, in command_line
    self.coverage.stop()
  File "/usr/local/lib/python2.7/dist-packages/coverage/control.py", line 389, in stop
    self.collector.stop()
  File "/usr/local/lib/python2.7/dist-packages/coverage/collector.py", line 262, in stop
    assert self._collectors[-1] is self
AssertionError
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/lib/python2.7/multiprocessing/util.py", line 284, in _exit_function
    info('process shutting down')
TypeError: 'NoneType' object is not callable
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/lib/python2.7/multiprocessing/util.py", line 284, in _exit_function
    info('process shutting down')
TypeError: 'NoneType' object is not callable

Name                               Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------------------------
dukeclient/__init__                   53     53      2      0     4%   1-93
dukeclient/commands/__init__          41     33      6      2    26%   1-9, 12, 14-15, 17, 24-28, 34-43, 46-63
...
4

1 回答 1

3

关于NoneType is not callable error,请在下面找到一些可能对您有所帮助的元素。

在您的模块plugintest.pynose-1.1.2-py2.7.egg/nose/plugins/,第 174 行,可以阅读以下行:

from multiprocessing import Manager

这导致multiprocessing.util包被导入,并随之注册一个退出函数:

atexit.register(_exit_function)

问题似乎multiprocessing.util是在被调用之前加载的plugintest内容然后被卸载_exit_function,顺便说一句,它是函数定义。

因此,如果您将其导入setup.py文件中:

from multiprocessing import util

错误消失。

顺便说一句,我不得不评论测试中失败的某些部分或更改某些代码行:

  • -m命令似乎无效;
  • 我不得不重命名duke_conf.ymlduke_conf.yml;
  • 检查文件是否存在的测试README.rst失败LICENSE(没有时间检查原因);

希望能帮助到你,

于 2012-08-29T20:59:02.670 回答