I have a package with the following layout:
tiny-py-interpreter/
|-- setup.py
|-- .coveragerc
|-- tinypy/
| -- foo/
| -- bar/
| -- tests/
| -- tinypyapp.py
| -- run_tests.py
Here are some lines from the setup.py:
setup(
...
packages=find_packages(),
entry_points = {
'console_scripts' : [ 'tinypy = tinypy.tinypyapp:main']
},
test_suite = 'tinypy.run_tests.get_suite',
)
After installing the package a console script called tinypy is installed:
pip3 install .
Then I run coverage:
coverage run setup.py test
coverage combine
coverage report
All the tests I have are implemented in a such way that each test launches a subprocess of the tinypy, so I use parallel = True in .coveragerc to capture the result of the coverage run.
Essentially, I have the same layout as coverage itself, where coverage and cmdline.py are the same things as tinypy and tinypyapp.py in my case.
The problem: when console script tinypy (tinypyapp.py) is executed, it uses an installed version of the tinypy package, which is located in /usr/local/lib/python3.5/site-packages/tinypy/. Coverage ignores sources in ./tinypy (as they're not used). If source parameter is omitted, that it's possible to see coverage for the code from site-packages/tinypy.
The question: how to structure the project properly? When tinypyapp.py is installed as a script, it is installed on the same level as tinypy folder (one level higher, not inside). I can't place tinypyapp.py outside the tinypy folder, as then setup.py can't find it. Because of this I can't use tinypyapp.py and have to use name of the script (which is tinypy).