diff options
author | Christophe de Vienne <christophe@unlish.com> | 2014-11-27 11:42:24 +0100 |
---|---|---|
committer | Christophe de Vienne <christophe@unlish.com> | 2014-11-27 11:42:24 +0100 |
commit | 36fa2febb554db2a11414a81e69da941a57c1ce4 (patch) | |
tree | e58db8f31ffafda36b5a9ee15ae60190e6d3abd8 /test | |
parent | 8606c33284a5577199da49e10f15b3880dd90147 (diff) | |
download | logilab-common-36fa2febb554db2a11414a81e69da941a57c1ce4.tar.gz |
[coverage] Provides better tools to pause tracing
The former implementation was not restoring properly the trace function on python 2.7 at least.
This cleaner implementation uses context-manager, and deprecates the pause_tracing/resume_tracing couple.
Closes #280757
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest_pytest.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/unittest_pytest.py b/test/unittest_pytest.py index 5496cf5..7966111 100644 --- a/test/unittest_pytest.py +++ b/test/unittest_pytest.py @@ -46,5 +46,56 @@ class ModuleFunctionTC(TestCase): self.assertTrue(this_is_a_testfile(join("coincoin", "unittest_bibi.py"))) self.assertFalse(this_is_a_testfile(join("unittest", "spongebob.py"))) + def test_replace_trace(self): + def tracefn(frame, event, arg): + pass + + oldtrace = sys.gettrace() + with replace_trace(tracefn): + self.assertIs(sys.gettrace(), tracefn) + + self.assertIs(sys.gettrace(), oldtrace) + + def test_pause_trace(self): + def tracefn(frame, event, arg): + pass + + oldtrace = sys.gettrace() + sys.settrace(tracefn) + try: + self.assertIs(sys.gettrace(), tracefn) + with pause_trace(): + self.assertIs(sys.gettrace(), None) + self.assertIs(sys.gettrace(), tracefn) + finally: + sys.settrace(oldtrace) + + def test_nocoverage(self): + def tracefn(frame, event, arg): + pass + + @nocoverage + def myfn(): + self.assertIs(sys.gettrace(), None) + + with replace_trace(tracefn): + myfn() + + def test_legacy_pause_resume_tracing(self): + def tracefn(frame, event, arg): + pass + + with replace_trace(tracefn): + pause_tracing() + self.assertIs(sys.gettrace(), None) + with replace_trace(tracefn): + pause_tracing() + self.assertIs(sys.gettrace(), None) + resume_tracing() + self.assertIs(sys.gettrace(), tracefn) + self.assertIs(sys.gettrace(), None) + resume_tracing() + self.assertIs(sys.gettrace(), tracefn) + if __name__ == '__main__': unittest_main() |