How to structure python project for use with coverage.py?
Question: 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](https://github.com/nedbat/coveragepy/blob/master/coverage/cmdline.py),
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`).


Answer: My current workaround is to create `test_entry_point.py` in the root folder:

    
    
    tiny-py-interpreter/
    |-- setup.py
    |-- test_entry_point.py
    |-- ...
    

With the following content:

    
    
    import sys
    from tinypy.tinypyapp import main
    
    if __name__ == '__main__':
        main()
    

And use the following filename when launching a subprocess in test:

    
    
    tinypy_binary = sys.executable + ' ' + os.getcwd() + '/test_entryp.py'
    subprocess.run(tinypy_binary, ...)
    

