From c79afb1cba6b155d85000902bdd467da48673f18 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 10 Jul 2019 08:25:05 -0700 Subject: [PATCH] Move ansible-test unit coverage code into plugin. --- test/runner/lib/executor.py | 11 +++++++++ .../plugins/ansible_pytest_coverage.py} | 24 ++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) rename test/units/{conftest.py => pytest/plugins/ansible_pytest_coverage.py} (78%) diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index 63bffe02773..f9a891f76a8 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -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') diff --git a/test/units/conftest.py b/test/units/pytest/plugins/ansible_pytest_coverage.py similarity index 78% rename from test/units/conftest.py rename to test/units/pytest/plugins/ansible_pytest_coverage.py index bc2bd646ab2..da4fc70e17d 100644 --- a/test/units/conftest.py +++ b/test/units/pytest/plugins/ansible_pytest_coverage.py @@ -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 +from __future__ import (absolute_import, division, print_function) -try: - import coverage -except ImportError: - coverage = None -try: - test = coverage.Coverage -except AttributeError: - coverage = None +def pytest_configure(): + try: + import coverage + except ImportError: + coverage = None + try: + test = coverage.Coverage + except AttributeError: + coverage = None -def pytest_configure(): if not coverage: return + import gc + import os + coverage_instances = [] for obj in gc.get_objects():