preventing python coverage from including virtual environment site packages

前端 未结 3 430
天命终不由人
天命终不由人 2021-02-06 20:38

I am new to coverage and ran into a strange problem. My coverage is taking my virtual environment site packages into account. Here is the output of the coverage run:

<         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 21:36

    Thanks to tknickman I figured it out: Use either

    coverage run --source  test.py
    

    or create a configuration file .coveragerc which resides in the directory you run coverage from, with the following content:

    [run]
    source =
        
    

    This provides you do not have your virtual environment installed under the project directory. If you have the virtual environment installed under the project dir you can use

    coverage run --source  --omit  test.py
    

    Note that omit wants a file pattern like

    ~/projectdir/venv/*
    

    instead of a path.

    The corresponding .coveragerc would look like this:

    [run]
    source=
        
    omit=
        //*
    

    I still think that like packages of the standard library any packages installed under site-packages should not be covered by default.

提交回复
热议问题