[TIP] how to configure automated python testing and code coverage reports

Ned Batchelder ned at nedbatchelder.com
Tue Dec 18 10:52:25 PST 2018


Hi Joe,

Add "--source=." to your coverage run line:

     coverage run --source=. subfolder/test_scriptA.py

--Ned.

On 12/18/18 10:44 AM, DZIOBEK, JOE wrote:
>
> Hello,
>
> I am a python pytest newbie, and am trying to configure automated 
> python testing and code coverage reports.
>
> The source code folder structure is as follows:
>
> script.py
>
> test_script.py
>
> subfolder/
>
>     scriptA.py
>
>     test_scriptA.py
>
> I want to configure tox to
>
> 1)Execute all test-*.py scripts
>
> 2)Find all .py scripts, and calculate their test coverage
>
> 3)Eventually I also want to upload this coverage report to sonar
>
> With below tox.ini:
>
> 1)All test_*.py scripts are found and executed
>
> 2)Coverage is only reported for the specific test_scriptA.py I list. 
> If I omit the specific test, I get errors.
>
> How can I configure ‘coverage’ to find all py files, and report on 
> their coverage?
>
> This is what I have so far in my tox.ini:
>
> [testenv]
>
> deps = pytest
>
>        coverage
>
> commands =
>
>     pytest --ignore=virtualenv-15.1.0/
>
>     coverage run subfolder/test_scriptA.py
>
>     coverage report –m
>
> Thanks for any advice - Joe
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20181218/494c0f1d/attachment.htm>


More information about the testing-in-python mailing list