pytest-cov collects no data on Travis

I recently switched from nosetests to pytest and pytest-cov for one of my Python project (http://easydev-python.readthedocs.io).

Locally, everything seemed to work fine and once on Travis, all tests passed as expected.

Yet, before the coverage report, I noticed this warning:

and more importantly, the final coverage reported was 0% !!

I later realised that one __init__.py file in the test/ directory was present locally but not in the github source code. After a commit, travis found the missing file and the coverage came back to normal.

So, this __init__.py seems important for pytest-cov

This entry was posted in Python and tagged , , . Bookmark the permalink.

7 Responses to pytest-cov collects no data on Travis

  1. hredestig says:

    Thanks man! Just hit by that one as well

  2. Dan Michael says:

    Same here. That is, it actually works fine for me locally without tests/__init__.py , and it used to do so on Travis as well. The versions of pytest etc. on Travis seems to be the same as I have locally, so I don’t really understand why it works locally and not there. Yet, adding tests/__init__.py fixed it

  3. John Didion says:

    Thanks Thomas! Just ran into this as well.

  4. glyg says:

    Thanks for the tip, helped me fix a long lasting problem…

    For info , I had to add __init__.py files to all the subdirs of my test dir., e.g
    tests/submod1/__init__.py, tests/submod2/__init__.py and so on.

  5. Rafid Aslam says:

    Thanks man, btw in my case, in local at first there was no __init__.py, and yeah like you said the Travis-CI warns about ” Coverage.py warning: No data was collected”, but it worked in local.

    And then I add __init__.py to my tests/ directory, and it works for either in local and travis-ci

  6. drbriefs says:

    So why is it that the pytest documentation state “You shouldn’t have __init__.py files in your test directories.”?
    https://pytest.readthedocs.io/en/reorganize-docs/new-docs/user/directory_structure.html

    • locally, you should not but on travis continuous integration you should. I suspect that this is because on Travis your are installing the package from the source.
      Yet, depending on your software configuration (in your setup.py file), if you do not have an __init__, then you test directories will not be included in the source bundle downloaded by travis.

Leave a Reply

Your email address will not be published.