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()