From aab568709324e3d90c0b493b18125c1f5d223dd6 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 5 Jun 2019 11:21:44 +0200 Subject: [PATCH] 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 35d5f9661..635e7a614 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -1,5 +1,20 @@ +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):