0

Coverage doesn't seem to be picking up the "coverage" of the tests in the directory tests. The source files are in a directory src. (File names have been changed to protect the innocent.)

Here is the tox.ini:

[tox]
envlist = py3


[testenv]
extras = test
commands =
    pip list --format=columns
    coverage run --rcfile=.coveragerc -m pytest --full-trace -l --strict -v
    coverage combine --append
    coverage report -im
    coverage html -i
exclude =
    .tox,
    .git,
    __pycache__,
    'src/reports',
    'src/target_files',
    test,
    venv


[flake8]
exclude =
    .tox,
    .git,
    __pycache__,
    'src/reports',
    'src/target_files',
    test,
    venv
max-line-length = 111

Here is the coveragerc:

[run]
branch=True
context=src
omit = test
source=
    src
timid=True
parallel=True
[report]
omit=
    .tox/*

Here is the setup.py:

from setuptools import setup
from setuptools import find_packages

_INSTALL_REQUIRES = [
    "pytest"
]
_EXTRAS_REQUIRE = {
  "test": [
    "flake8",
    "coverage",
    "mock",
    "setuptools"
  ]
}

setup(
    author='...',
    author_email='...',
    description='',
    extras_require=_EXTRAS_REQUIRE,
    include_package_data=True,
    install_requires=_INSTALL_REQUIRES,
    license='',
    name='...',
    package_dir={'': 'src'},
    packages=find_packages(where="src"),
    url='',
    version='1'
)

This outputs:

Coverage.py warning: No data was collected. (no-data-collected)
py3 run-test: commands[2] | coverage combine --append
py3 run-test: commands[3] | coverage report -im
Name                               Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------------------------
src/__init__.py                        0      0      0      0   100%
src/[file].py                          7      7      0      0     0%   1- 13
src/[file].py                         13     13      0      0     0%   1-18
src/lib/__init__.py                    0      0      0      0   100%
src/lib/[file].py                     83     83     26      0     0%   1-161
src/lib/[file].py                     49     49     16      0     0%   1-67
src/lib/[file].py                     92     92     22      0     0%   1-117
src/lib/[file].py                     47     47     20      0     0%   1-71
src/lib/[file].py                     34     34      8      0     0%   1-42
------------------------------------------------------------------------------
TOTAL                                325    325     92      0     0%

There are tests for each of the files in this list. What can I do to get coverage to notice them?

2 Answers 2

2

There is no python package named src in your environment. It should match the name of your package (which you've replaced with ...).

[run]
# Change this to your package name. 
source=
    src
Sign up to request clarification or add additional context in comments.

Comments

1

Ensure you add an __init__.py file to the tests folder. That should be enough for coverage to pick them up.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.