Unhelpful warnings produced when using source directive and subprocess measurement

Issue #96 resolved
Geoff Bache created an issue

When I specify my source in the [run] section of the rc file, and run coverage by setting COVERAGE_PROCESS_START, I get a lot of spurious warnings printed on standard error.

It says "Source module %s was never encountered." and occasionally "No data was collected."

Obviously not every subprocess will necessarily load every source module, and indeed it's perfectly OK to have some python subprocess somewhere which doesn't run any of my code.

The first warning is also a pain when running multiple tests in different processes: I want to have one rc file saying where my source is without needing every test to load every module.

I'd question whether these warnings are useful at all: but at least there should be some way to disable them, and preferably they should be off by default.

Comments (14)

  1. Ned Batchelder repo owner

    I definitely see your points here. The purpose of the warnings was to help people new to coverage to diagnose why they weren't getting the results they expected. So I'm going to leave them enabled by default. We can either disable them entirely with an rcfile setting, or provide a way to disable them individually, which is probably overkill.

  2. Geoff Bache reporter

    OK. Couldn't you achieve the first point with some kind of --debug / --verbose option? (i.e. documented as "enable this if you don't understand what's going on"?)

    I see your point re newbies but I think it isn't good to have things enabled by default that will often just be wrong. As far as I can see, they're only really useful if you're testing a single process in their current form.

  3. wigbam

    This issue caused some pain to us as well. We are using pytest (and therefore pytest-cov and cov-core) to run tests within our company. When pytest-cov runs it creates coverage controller with explicit set of modules to collect coverage for, which is then also applied to all sub-processes (as far as my understanding goes).

    Since a few of our tests parse the output from a sub-process they were failing due to warnings from coverage being present in the output. In the end I had to patch coverage to provide a possibility to disable all coverage warnings by setting an environment variable.

    Therefore, in ideal case I would vouch for disabling coverage warnings for all sub-processes by default and only display them when aggregated output is generated at the test session end. Not sure if this needs to go into pytest-cov/cov-core or into coverage itself, though.

  4. Chris Withers

    Is there yet a way to suppress these warnings:

    Coverage.py warning: No data was collected. Coverage.py warning: {modname} archivist was never imported.

    I did have a look at #355, but seems pretty empty...

  5. Simon Ye

    It seems like an easy-ish thing to add to the config to control self._warn_no_data = True, self._warn_unimported_source = True in control.py.

    I'm also getting these warnings run through pytest-cov, so a config variable should do the trick nicely.

  6. Ned Batchelder repo owner

    I liked the idea of individually suppressable warnings, rather than a huge hammer that turns them all off. Other opinions?

  7. Loic Dachary

    :-D what about --no-warnings=no_data,unimported_source to only set

    self._warn_no_data = False
    self._warn_unimported_source = False
  8. Log in to comment