Thanks to tknickman I figured it out: Use either
coverage run --source <path to project dir> test.py
or create a configuration file .coveragerc which resides in the directory you run coverage from, with the following content:
[run]
source =
<path to project dir>
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 <project path> --omit <pattern> 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=
<path to project dir>
omit=
<path to project dir>/<name of virtual env>/*
I still think that like packages of the standard library any packages installed under site-packages should not be covered by default.