我对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
...
答案 0 :(得分:3)
关于NoneType is not callable error
,请在下面找到一些可能对您有帮助的元素。
在plugintest.py
第174行的nose-1.1.2-py2.7.egg/nose/plugins/
模块中,您可以阅读以下内容:
from multiprocessing import Manager
这导致导入multiprocessing.util
包,并带有要注册的退出函数:
atexit.register(_exit_function)
问题似乎是multiprocessing.util
中加载的plugintest
然后在_exit_function
被调用之前被卸载,顺便说一下它是函数定义。
因此,如果您将其导入setup.py
文件:
from multiprocessing import util
错误消失。
顺便说一句,我不得不在测试失败或改变某些代码行的部分进行评论:
-m
命令似乎无效; duke_conf.yml
重命名为duke_conf.yml
; README.rst
和LICENSE
文件是否存在的测试失败(没有时间检查原因); 希望它有所帮助,