Python: AssertionError when running nose tests with scope

I'm pretty green with python testing, so this might be something that I am doing wrong.

When I run my tests, the test runners work fine and cover too .. but between the two I get an assertion error:

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 

To complicate the task, I am trying to check the command line utility. This means that I had to tell coverage to cover subprocess calls.

I think I got this part since coverage currently reports% coverage for running the script. But since I got coverage, I cannot get rid of AssertionError.

Some help in understanding what would be wrong to appreciate. All my code is available on github:

Quick start:

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

thanks

Update

I ran the test on another computer and got the same AssertionError .. plus a new TypeError. Again, the tests run correctly, and the coverage also works fine even with these errors.

 ... 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 ... 
+6
source share
1 answer

As for NoneType is not callable error , find below some elements that might help you.

In your plugintest.py module from nose-1.1.2-py2.7.egg/nose/plugins/ , line 174, you can read the following line:

 from multiprocessing import Manager 

This leads to the fact that the multiprocessing.util package must be imported and the exit function must be registered with it:

 atexit.register(_exit_function) 

The problem is that multiprocessing.util loaded into plugintest is then unloaded before the _exit_function , and it defines function definitions.

Thus, if you import it into your setup.py :

 from multiprocessing import util 

The error will disappear.

By the way, I had to comment on some parts of the tests that did not run or changed some lines of code:

  • the -m command seems invalid;
  • I had to rename duke_conf.yml to duke_conf.yml ;
  • tests that check whether the README.rst and LICENSE files README.rst do not work (there was no time to check why);

Hope this helps,

+3
source

Source: https://habr.com/ru/post/908848/


All Articles