microsoft / ptvsd

Python debugger package for use with Visual Studio and Visual Studio Code.
Other
548 stars 68 forks source link

ptvsd import suppresses coverage reporting #2114

Closed rjungwirth closed 4 years ago

rjungwirth commented 4 years ago

Environment data

Actual behavior

import ptvsd module suppresses coverage reporting for all execution after import

Expected behavior

importing ptvsd should not cause coverage reporting to be supressed

Steps to reproduce:

  1. run this bash script:
    #!/usr/bin/env bash
    rm -rf _venv
    python3 -m venv _venv
    ./_venv/bin/pip3 install --upgrade pip
    ./_venv/bin/pip3 install coverage ptvsd
    cat >foo_test.py<<EOF
    import sys
    if len(sys.argv) > 1: import ptvsd
    def do_something(x):
    return x
    do_something(5)
    EOF
    _venv/bin/coverage run --omit=_venv/* foo_test.py
    if $(_venv/bin/coverage report | fgrep foo_test.py | fgrep -q '100%'); then echo 'NO IMPORT PTVSD SUCCESS'; else echo 'NO IMPORT PTVSD FAILURE ';fi
    _venv/bin/coverage run --omit=_venv/* foo_test.py 1
    if $(_venv/bin/coverage report | fgrep foo_test.py | fgrep -q '100%'); then echo 'IMPORT PTVSD SUCCESS'; else echo 'IMPORT PTVSD FAILURE';fi

    observe:

test case 1 succeeds (no importing PTVSD == full coverage reporting)

test case 2 fails: importing PTVSD causes coverage reporting to stop for all subsequent execution steps in script

rjungwirth commented 4 years ago

this is a big "gotcha"! Simply importing PTVSD suppresses code coverage regardless of whether you use the functionality or not.

Please add a note to the documentation so others don't waste their time figuring out what is wrong with their code!

int19h commented 4 years ago

This shouldn't be the case for ptvsd 5.x / debugpy anymore, since it doesn't import pydevd unless and until the module is actually used - merely importing it does nothing.