"--source Coverage.py warning: Module xxx.py was never imported" using "-m unittest discover -v tests" on CircleCI Fails

Issue #567 invalid
Former user created an issue

I try the command "coverage run --source validate_config_files.py -m unittest discover -v tests" locally using Ubuntu and works. I get the message "Ok" in the end of the tests execution. However, executing the same command in CircleCI fails, saying that "Coverage.py warning: Module validate_config_files.py was never imported." and so that no coverage data was generated.


  • Is there a workaround for the generate report only for source validate_config_files.py in a different way?
  • Removing the switch I get code coverage for ALL files in python. Since I'm generating HTML reports, Is there a way to filter which files to include during the report?
coverage run --source validate_config_files.py -m unittest discover -v tests
test_all_properties_are_valid (test_all_valid_config_validation.AllSuccessfulTests) ... All config files are valid
 is tests/fixtures/all-valid-config/publisher-prd.yml valid? True
 is tests/fixtures/all-valid-config/publisher-e2e.yml valid? True
 is tests/fixtures/all-valid-config/publisher-onboard_preprod.yml valid? True
 is tests/fixtures/all-valid-config/publisher-prf.yml valid? True

Ran 10 tests in 0.433s

Coverage.py warning: Module validate_config_files.py was never imported.
Coverage.py warning: No data was collected.

Comments (4)

  1. Ned Batchelder repo owner

    The warning shows that coverage.py thinks you are referring to a module, not a file. Why that happens on CircleCI? Maybe the code layout is different? When you use --source file.py, if file.py is a path that exists, then coverage.py knows it is a file. If the path doesn't exist, then coverage guesses that you mean a module. But if you never execute "import file.py", then it thinks the module hasn't been imported. Of course, you don't have a file/py.py, or a file/py/init.py, so "import file.py" will never happen.

  2. Ned Batchelder repo owner

    Since this was filed anonymously, I doubt I will hear back from the original poster. If you need to, re-open this issue with more details.

  3. Vasily Ryabov

    Nevermind. Finally I've figured out it works after replacing --source with --include. The docs are saying --source is for directories only.

  4. Log in to comment