'assert self._collectors' when trying to measure coverage of profilehooks

Issue #273 invalid
Marius Gedminas created an issue

Steps to reproduce:

  1. git clone http://github.com/mgedmin/profilehooks
  2. cd profilehooks
  3. coverage run test_profilehooks.py

What I get with coverage 3.7:

Ran 4 tests in 0.005s


Traceback (most recent call last):
  File "/home/mg/.venv/bin/coverage", line 9, in <module>
    load_entry_point('coverage==3.7', 'console_scripts', 'coverage')()
  File "/home/mg/.venv/local/lib/python2.7/site-packages/coverage/cmdline.py", line 720, in main
    status = CoverageScript().command_line(argv)
  File "/home/mg/.venv/local/lib/python2.7/site-packages/coverage/cmdline.py", line 438, in command_line
    self.do_execute(options, args)
  File "/home/mg/.venv/local/lib/python2.7/site-packages/coverage/cmdline.py", line 580, in do_execute
  File "/home/mg/.venv/local/lib/python2.7/site-packages/coverage/control.py", line 410, in stop
  File "/home/mg/.venv/local/lib/python2.7/site-packages/coverage/collector.py", line 293, in stop
    assert self._collectors

Now this may be caused by profilehooks doing nasty stuff like calling sys.settrace(), and I'm fine if that's not supported by coverage, but I think the error message could be better.

Comments (3)

  1. Ned Batchelder repo owner

    It turns out this isn't related to profilehooks specifically at all. I reduced your test program to this:

    import atexit

    and it produced the message shown.

    Your tests do this, but it doesn't seem wise. Running the atexit functions through an unsupported interface seems to mean that they are being run twice: once when you call them, and then again at the termination of the process.

    Perhaps you could achieve your tests' goals a different way?

  2. Marius Gedminas reporter

    Yep, I should just stub atexit.register in my tests.

    In my defence, profilehooks was written in 2004 when I was young and somewhat more stupid than I still am today.

  3. Log in to comment