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

Marius Gedminas marius at gedmin.as
Wed Dec 19 01:20:39 PST 2018


On Tue, Dec 18, 2018 at 03:44:46PM +0000, DZIOBEK, JOE wrote:
> 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

Make this

  commands =
      coverage run -m pytest --ignore=...
      coverage report -m

And add a .coveragerc with

  [run]
  source = .

I'm not sure what the "--ignore=virtualenv-15.1.0/" bit is about.  If
you find coverage report reporting about paths in virtualenv-15.1.0/,
you may need to add an

  omit = virtualenv-15.1.0/*

or something similar to the .coveragerc.

HTH,
Marius Gedminas
-- 
Experience varies directly with equipment ruined.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20181219/79a2bdea/attachment.pgp>


More information about the testing-in-python mailing list