Move ansible-test unit coverage code into plugin.

This commit is contained in:
Matt Clay 2019-07-10 08:25:05 -07:00
parent 49a1ec40aa
commit c79afb1cba
2 changed files with 25 additions and 12 deletions

View file

@ -1333,6 +1333,17 @@ def command_units(args):
'test/results/junit/python%s-units.xml' % version,
]
plugins = []
if args.coverage:
plugins.append('ansible_pytest_coverage')
if plugins:
env['PYTHONPATH'] += ':%s' % os.path.join(INSTALL_ROOT, 'test/units/pytest/plugins')
for plugin in plugins:
cmd.extend(['-p', plugin])
if args.collect_only:
cmd.append('--collect-only')

View file

@ -1,22 +1,24 @@
"""Monkey patch os._exit when running under coverage so we don't lose coverage data in forks, such as with `pytest --boxed`."""
import gc
import os
try:
import coverage
except ImportError:
coverage = None
try:
test = coverage.Coverage
except AttributeError:
coverage = None
from __future__ import (absolute_import, division, print_function)
def pytest_configure():
try:
import coverage
except ImportError:
coverage = None
try:
test = coverage.Coverage
except AttributeError:
coverage = None
if not coverage:
return
import gc
import os
coverage_instances = []
for obj in gc.get_objects():