question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`coverage run` does not ignore .venv dir, so it tracks all dependencies and python internal files

See original GitHub issue

Describe the bug A clear and concise description of the bug.

To Reproduce How can we reproduce the problem? Please be specific.

  1. What version of Python are you using? Python 3.7.4
  2. What version of coverage.py are you using? The output of coverage debug sys is helpful.
    -- sys -------------------------------------------------------
                version: 4.5.4
                coverage: /Users/h14384/Documents/work/cm-ch-engine/venv/lib/python3.7/site-packages/coverage/__init__.py
            cover_paths: /Users/h14384/Documents/work/cm-ch-engine/venv/lib/python3.7/site-packages/coverage
            pylib_paths: /Users/h14384/.pyenv/versions/3.7.4/lib/python3.7
                tracer: CTracer
    plugins.file_tracers: -none-
    plugins.configurers: -none-
            config_files: .coveragerc
                        setup.cfg
                        tox.ini
            configs_read: -none-
                data_path: /Users/h14384/Documents/work/cm-ch-engine/.coverage
                python: 3.7.4 (default, Aug 15 2019, 12:39:43) [Clang 10.0.1 (clang-1001.0.46.4)]
                platform: Darwin-18.7.0-x86_64-i386-64bit
        implementation: CPython
            executable: /Users/h14384/Documents/work/cm-ch-engine/venv/bin/python
                    cwd: /Users/h14384/Documents/work/cm-ch-engine
                    path: 
                        /Users/h14384/.pyenv/versions/3.7.4/lib/python37.zip
                        /Users/h14384/.pyenv/versions/3.7.4/lib/python3.7
                        /Users/h14384/.pyenv/versions/3.7.4/lib/python3.7/lib-dynload
                        /Users/h14384/Documents/work/cm-ch-engine/venv/lib/python3.7/site-packages
            environment: PYENV_SHELL = zsh
            command_line: /Users/h14384/Documents/work/cm-ch-engine/venv/bin/coverage debug sys
            source_match: -none-
        source_pkgs_match: -none-
            include_match: -none-
            omit_match: -none-
            cover_match: /Users/h14384/Documents/work/cm-ch-engine/venv/lib/python3.7/site-packages/coverage
            pylib_match: /Users/h14384/.pyenv/versions/3.7.4/lib/python3.7

  1. What versions of what packages do you have installed? The output of pip freeze is helpful.
    astroid==2.2.5
    autopep8==1.4.3
    boto3==1.9.208
    botocore==1.12.208
    certifi==2018.11.29
    chardet==3.0.4
    coverage==4.5.4
    Django==2.1.3
    django-debug-toolbar==2.0
    django-silk==3.0.2
    djangorestframework==3.9.0
    docutils==0.14
    fsspec==0.4.4
    gprof2dot==2016.10.13
    idna==2.8
    isort==4.3.21
    Jinja2==2.10
    jmespath==0.9.4
    lazy-object-proxy==1.4.1
    MarkupSafe==1.1.0
    mccabe==0.6.1
    memory-profiler==0.55.0
    mysqlclient==1.4.4
    numpy==1.16.4
    pandas==0.25.0
    pbr==5.1.1
    pep8==1.7.1
    psutil==5.6.3
    psycopg2==2.8.3
    pyarrow==0.14.1
    pycodestyle==2.4.0
    Pygments==2.3.1
    pylint==2.3.1
    pylint-django==2.0.11
    pylint-plugin-utils==0.5
    pymongo==3.9.0
    PyMySQL==0.9.3
    python-dateutil==2.7.5
    pytz==2018.7
    requests==2.21.0
    rope==0.14.0
    s3fs==0.3.3
    s3transfer==0.2.1
    scipy==1.3.0
    selenium==3.141.0
    six==1.11.0
    sqlparse==0.2.4
    stevedore==1.30.0
    typed-ast==1.4.0
    urllib3==1.24.1
    virtualenv==16.1.0
    virtualenv-clone==0.4.0
    virtualenvwrapper==4.8.2
    wrapt==1.11.2
  1. What code are you running? Give us a specific commit of a specific repo that we can check out.

A Django app

  1. What commands did you run?

coverage run manage.py test

Expected behavior Coverage for my project files only, not every file in the environment including the python standard library.

Additional context

    venv/lib/python3.7/site-packages/urllib3/util/request.py                                                                  45     36    20%
    venv/lib/python3.7/site-packages/urllib3/util/response.py                                                                 35     29    17%
    venv/lib/python3.7/site-packages/urllib3/util/retry.py                                                                   150    102    32%
    venv/lib/python3.7/site-packages/urllib3/util/ssl_.py                                                                    147    114    22%
    venv/lib/python3.7/site-packages/urllib3/util/timeout.py                                                                  59     29    51%
    venv/lib/python3.7/site-packages/urllib3/util/url.py                                                                     103     87    16%
    venv/lib/python3.7/site-packages/urllib3/util/wait.py                                                                     77     59    23%
    ------------------------------------------------------------------------------------------------------------------------------------------
    TOTAL                                                                                                                 221690 156052    30%

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

6reactions
zees-devcommented, Sep 30, 2020

The following command could work: coverage run --omit 'venv/*' -m unittest tests/*.py && coverage report -m

4reactions
therearesomewhocallmetimcommented, May 1, 2020

I am not using .venv, but poetry, and the dependencies folder is not in my project folder. However, I still get all the dependencies in my coverage report. Is there a way for me to exclude the dependencies?

Read more comments on GitHub >

github_iconTop Results From Across the Web

testing - preventing python coverage from including virtual ...
I had the virtual environment at first inside the project directory and now moved it out to ~/Envs with virtualenvwrapper, but the problem...
Read more >
Release 7.0.0b1 unknown - Coverage.py
Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts.
Read more >
PyScaffold Documentation
PyScaffold is a project generator for bootstrapping high-quality Python packages, ready to be shared on PyPI and installable via pip.
Read more >
subshop - Python Package Health Analysis | Snyk
--user # ---OR--- do a virtualenv install $ cd subshop $ python3 -m venv .venv $ source .venv/bin/activate $ pip3 install . #...
Read more >
pipenv Documentation
run will run a given command from the virtualenv, with any ... If you do not have Python, please install the latest 3.x...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found