Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line 0 reported as "missing" in coverage report #585

Open
psjamesh opened this issue Mar 3, 2023 · 1 comment
Open

Line 0 reported as "missing" in coverage report #585

psjamesh opened this issue Mar 3, 2023 · 1 comment

Comments

@psjamesh
Copy link

psjamesh commented Mar 3, 2023

When running pytest with the --cov option, the report contains "missing" entries for a few files with line number 0 reported as the culprit. Not all files exhibit this issue and there is no obvious correlation between the files that do.

We are running tests using tox. See various configuration items below which might help with debugging the issue.


A file which is reported as having a "missing" entry on line 0.

from knox.views import LoginView as KnoxLoginView
from rest_framework.authentication import BasicAuthentication


class LoginView(KnoxLoginView):
    authentication_classes = [BasicAuthentication]

Extract from the coverage report (XML) for this file:

......
        <class name="views.py" filename="src/apps/api_auth/views.py" complexity="0" line-rate="0.8" branch-rate="0">
                <methods/>
                <lines>
                        <line number="0" hits="0"/>
                        <line number="1" hits="1"/>
                        <line number="2" hits="1"/>
                        <line number="5" hits="1"/>
                        <line number="6" hits="1"/>
                </lines>
        </class>
......

Contents of tox.ini:

[tox]
env_list =
    flake8
    black
    py311
requires =
    tox>4
    virtualenv>20.2

[gh-actions]
python =
    3.11: flake8,black,py311

[testenv:flake8]
description = install flake8 in a virtual environment and invoke it from the root of the project
deps = flake8
commands = flake8 .

[testenv:black]
description = install black in a virtual environment and invoke it from the root of the project
deps = black
commands = black --diff --check .

[testenv]
description = install pytest in a virtual environment and invoke it from the root of the project, outputting junit and coverage reports to a reports folder.
deps =
    -r requirements-test.txt
commands = pytest --junitxml=reports/unit-test-{envname}.xml --cov=. --cov-report=xml:reports/pytest-cov-{envname}.xml --cov-fail-under=95 -vvv {posargs}

Contents of .coveragerc:

[run]
omit =
    tests/**/*
    **/migrations/*
    **/.tox/**/*
    **/venv/**/*
    **/.venv/**/*

source = src/

Contents of pytest.ini:

[pytest]
DJANGO_SETTINGS_MODULE = deploydocus_project.settings
python_files = tests.py test_*.py *_tests.py
pythonpath = src
testpaths = tests
addopts = -p no:warnings --strict-markers --no-migrations --reuse-db --import-mode importlib

Contents of requirements-test.txt:

uWSGI==2.0.21
dependency-injector==4.41.0
Django==4.1.7
django-allow-cidr==0.6.0
django-environ==0.9.0
django-health-check==3.17.0
django-prometheus==2.2.0
djangorestframework==3.14.0
django-rest-knox==4.2.0
prometheus-client==0.16.0
psycopg2-binary==2.9.5
whitenoise==6.3.0

pytest
pytest-cov==4.0.0
pytest-django
parameterized
assertpy
mutatest
flatten-dict
@abompard
Copy link

Probably related to nedbat/coveragepy#1419

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants