From 738180d24091b459830ffae2c4f532a711aa2418 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 12 Jun 2024 15:47:58 -0700 Subject: [PATCH] ansible-test - Fix unit test coverage collection (#83433) --- .../_util/target/pytest/plugins/ansible_pytest_coverage.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/lib/ansible_test/_util/target/pytest/plugins/ansible_pytest_coverage.py b/test/lib/ansible_test/_util/target/pytest/plugins/ansible_pytest_coverage.py index 577a498e253..efc8e931931 100644 --- a/test/lib/ansible_test/_util/target/pytest/plugins/ansible_pytest_coverage.py +++ b/test/lib/ansible_test/_util/target/pytest/plugins/ansible_pytest_coverage.py @@ -53,6 +53,12 @@ def pytest_configure(): def coverage_exit(*args, **kwargs): for instance in coverage_instances: + # skip coverage instances which have no collector, or the collector is not the active collector + # this avoids issues with coverage 7.4.0+ when tests create subprocesses which inherit our overridden os._exit method + # pylint: disable=protected-access + if not instance._collector or not instance._collector._collectors or instance._collector != instance._collector._collectors[-1]: + continue + instance.stop() instance.save()