2

When trying to run tests with coverage under Django + django-nose in PyCharm, I can't seem to get the coverage report to work. I've tried with the bundled coverage.py and without. Without the bundled coverage.py I see:

Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/helpers/coverage_runner/run_coverage.py", line 44, in <module> main() File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/cmdline.py", line 741, in main status = CoverageScript().command_line(argv) File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/cmdline.py", line 481, in command_line return self.do_run(options, args) File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/cmdline.py", line 625, in do_run self.coverage.stop() File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/control.py", line 692, in stop self.collector.stop() File "/Users/dane/.virtualenvs/dhp/lib/python3.5/site-packages/coverage/collector.py", line 277, in stop "Expected current collector to be %r, but it's %r" % (self, self._collectors[-1]) AssertionError: Expected current collector to be <Collector at 0x10e0cfbe0: CTracer>, but it's <Collector at 0x10fa368d0: CTracer> 

While with it I see:

Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/helpers/coverage_runner/run_coverage.py", line 44, in <module> main() File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/cmdline.py", line 721, in main status = CoverageScript().command_line(argv) File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/cmdline.py", line 438, in command_line self.do_execute(options, args) File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/cmdline.py", line 580, in do_execute self.coverage.stop() File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/control.py", line 410, in stop self.collector.stop() File "/Applications/PyCharm.app/Contents/helpers/coveragepy/coverage/collector.py", line 294, in stop assert self._collectors[-1] is self AssertionError 

My tests and coverage reporting work correctly via the command line, i.e.:

$ python manage.py test 

I've set up a Run Configuration using the Django tests template and I'm not doing anything special or out of the ordinary, as far as I'm aware. Has anyone run into this and solved it? Coverage integration would be very useful!

Update

This issue has been opened with JetBrains here.

1 Answer 1

1

I'm assuming that you have something similar to this in your config:

NOSE_ARGS = [ '--with-coverage', '--cover-package=foo,bar' ] 

PyCharm's coverage blows up when this is configured. I assume that it's either running two instances of coverage, or the coverage output is something other than it expected to parse. Either way, it seems that you can't use it at the moment.

Solutions for now:

  • remove NOSE_ARGS config, and if any of your automated/continuous integration tools need it, run them with the coverage options on the command line: python manage.py test --with-coverage --cover-package=foo (I chose this option because of the benefits in PyCharm)
  • don't use coverage in PyCharm

Note: I was able to find someone else with this problem here.

Sign up to request clarification or add additional context in comments.

2 Comments

KFunk you are correct that I've got those values in my NOSE_ARGS. I concur that removing them allows PyCharm to play nicely. In the meantime I've opened a bug (perhaps it's a feature request) with JetBrains and I've seen a small amount of movement there. We'll see what comes of it! I'm accepting your answer because it is the most correct thing for now, as sad as that makes me.
When/if jetbrains gets back to you with a public ticket ID, would you mind updating your Question to include that link at the bottom? I'll be posting on that ticket, and other might want to as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.