[ADD] mergebot: support for coverage during tests

Runs the test instances of Odoo using `coverage` in parallel mode.

- useful for finding out under-tested parts of the code
- because it only instruments mergeport/forwardport, and the tests do
  so much IO, the wallclock performance impacts are minimal (~2%
  increase with branch coverage analysis, for an increase in CPU
  of ~20%, for the entire testsuite)
- for reporting, the scattered coverage reports need to be aggregated
  using `coverage combine`, followed by rendering with `coverage
  html`, these work out of the box, no parameterization is necessary
- coverage does not run on the test suite, only the modules under test
This commit is contained in:
Xavier Morel 2022-10-27 11:25:25 +02:00
parent 13f239826e
commit 1449937e00

View File

@ -76,6 +76,7 @@ def pytest_addoption(parser):
parser.addoption('--addons-path')
parser.addoption("--no-delete", action="store_true", help="Don't delete repo after a failed run")
parser.addoption('--log-github', action='store_true')
parser.addoption('--coverage', action='store_true')
parser.addoption(
'--tunnel', action="store", type="choice", choices=['', 'ngrok', 'localtunnel'], default='',
@ -372,7 +373,13 @@ def server(request, db, port, module, dummy_addons_path, tmpdir):
request.config.getoption('--addons-path'),
dummy_addons_path,
]))
cov = []
if request.config.getoption('--coverage'):
cov = ['coverage', 'run', '-p', '--source=odoo.addons.runbot_merge,odoo.addons.forwardport', '--branch']
p = subprocess.Popen([
*cov,
'odoo', '--http-port', str(port),
'--addons-path', addons_path,
'-d', db,