From 1b7597ac912e76aef2e3c09dd815cb4208dcf817 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 5 Jun 2019 11:21:44 +0200 Subject: [PATCH] [4.6] tests: restore tracing function Without this, `testing/test_pdb.py` (already without pexpect) will cause missing test coverage afterwards (for the same process). --- testing/conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/testing/conftest.py b/testing/conftest.py index 6e01d710d11..627ee763d2f 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -1,6 +1,21 @@ # -*- coding: utf-8 -*- +import sys + import pytest +if sys.gettrace(): + + @pytest.fixture(autouse=True) + def restore_tracing(): + """Restore tracing function (when run with Coverage.py). + + https://bugs.python.org/issue37011 + """ + orig_trace = sys.gettrace() + yield + if sys.gettrace() != orig_trace: + sys.settrace(orig_trace) + @pytest.hookimpl(hookwrapper=True, tryfirst=True) def pytest_collection_modifyitems(config, items):