Move ansible-test unit coverage code into plugin.

pull/58957/head
Matt Clay 5 years ago
parent 49a1ec40aa
commit c79afb1cba

@ -1333,6 +1333,17 @@ def command_units(args):
'test/results/junit/python%s-units.xml' % version, '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: if args.collect_only:
cmd.append('--collect-only') cmd.append('--collect-only')

@ -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`.""" """Monkey patch os._exit when running under coverage so we don't lose coverage data in forks, such as with `pytest --boxed`."""
import gc from __future__ import (absolute_import, division, print_function)
import os
try:
def pytest_configure():
try:
import coverage import coverage
except ImportError: except ImportError:
coverage = None coverage = None
try: try:
test = coverage.Coverage test = coverage.Coverage
except AttributeError: except AttributeError:
coverage = None coverage = None
def pytest_configure():
if not coverage: if not coverage:
return return
import gc
import os
coverage_instances = [] coverage_instances = []
for obj in gc.get_objects(): for obj in gc.get_objects():
Loading…
Cancel
Save