SystemExit error in unittest and AssertionError in coverage with multiprocessing

Issue #372 closed
Abdeali Kothari created an issue

I am calling my test using subprocess.Popen(["python", "-m", "coverage", "run", "ServerTest"] and inside ServerTest.py I am spawning a subprocess to create a server to test on. I need to enable coverage on the subprocess spawned. The subprocess is spawned using subprocess.Popen(["python", "-m", "coverage", "run", __file__, "server"]) - so, it just adds an argument to the same file.

I added the env variable COVERAGE_PROCESS_START and called coverage.process_startup() inside the ServerTest.py but I am getting the following errors :

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/coverage/cmdline.py", line 575, in do_execute
    self.run_python_file(filename, args)
  File "/usr/lib/python3/dist-packages/coverage/execfile.py", line 104, in run_python_file
    exec_code_object(code, main_mod.__dict__)
  File "/usr/lib/python3/dist-packages/coverage/backward.py", line 93, in exec_code_object
    exec(code, global_map)
  File "/mnt/data/gnome/jhbuild/other-installs/coala/coalib/tests/output/dbus/DbusServerTest.py", line 103, in <module>
    unittest.main(verbosity=2)
  File "/usr/lib/python3.4/unittest/main.py", line 93, in __init__
    self.runTests()
  File "/usr/lib/python3.4/unittest/main.py", line 246, in runTests
    sys.exit(not self.result.wasSuccessful())
SystemExit: False

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/coverage/__main__.py", line 4, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/coverage/cmdline.py", line 721, in main
    status = CoverageScript().command_line(argv)
  File "/usr/lib/python3/dist-packages/coverage/cmdline.py", line 438, in command_line
    self.do_execute(options, args)
  File "/usr/lib/python3/dist-packages/coverage/cmdline.py", line 580, in do_execute
    self.coverage.stop()
  File "/usr/lib/python3/dist-packages/coverage/control.py", line 410, in stop
    self.collector.stop()
  File "/usr/lib/python3/dist-packages/coverage/collector.py", line 294, in stop
    assert self._collectors[-1] is self
AssertionError

I was able to suppress the first error by using the exit kwarg : unittest.main(exit=False) but I cannot figure out the second error about AssertionError.

Note : The python3 -m coverage ServerTest server has a Glib loop running inside it - it's basically a dbus server.

Edit: My codes can be found at https://github.com/AbdealiJK/coala/tree/ajk/dbus it can be run using ./run_tests.py -c -t DbusServerTest

Comments (6)

  1. Ned Batchelder repo owner

    Sorry for the long delay in looking into this. Your GitHub branch is gone. Have you fixed this problem?

  2. Abdeali Kothari reporter

    Hi Loic, Thanks for looking into this but I think I should close this because we completely revamped the testing framework and use pytest. Plus the code which had the issue has been removed now.

    Closing this issue as it does not affect me anymore.

  3. Log in to comment