[Python-checkins] bpo-34171: Prevent creating Lib/trace.cover when run the trace module. (GH-8841)

Miss Islington (bot) webhook-mailer at python.org
Sat Aug 25 03:47:25 EDT 2018


https://github.com/python/cpython/commit/80e9fedcf579537c5bc51ff3c9c18d14d9598564
commit: 80e9fedcf579537c5bc51ff3c9c18d14d9598564
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-08-25T03:47:22-04:00
summary:

bpo-34171: Prevent creating Lib/trace.cover when run the trace module. (GH-8841)

(cherry picked from commit c406d5cd74002964a64c3eb7d9e2445a7fd3a03f)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
A Misc/NEWS.d/next/Library/2018-08-21-00-29-01.bpo-34171.6LkWav.rst
M Lib/test/test_trace.py
M Lib/trace.py

diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index dc9b3fa7b6af..3b335ca42f90 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -387,6 +387,11 @@ def tearDown(self):
     def test_cover_files_written_no_highlight(self):
         argv = '-m trace --count'.split() + [self.codefile]
         status, stdout, stderr = assert_python_ok(*argv)
+        self.assertEqual(stderr, b'')
+        tracedir = os.path.dirname(os.path.abspath(trace.__file__))
+        tracecoverpath = os.path.join(tracedir, "trace.cover")
+        self.assertFalse(os.path.exists(tracecoverpath))
+
         self.assertTrue(os.path.exists(self.coverfile))
         with open(self.coverfile) as f:
             self.assertEqual(f.read(),
diff --git a/Lib/trace.py b/Lib/trace.py
index 16c3494689dd..86b2101763bf 100755
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -63,14 +63,6 @@
 
 import threading
 
-def _settrace(func):
-    threading.settrace(func)
-    sys.settrace(func)
-
-def _unsettrace():
-    sys.settrace(None)
-    threading.settrace(None)
-
 PRAGMA_NOCOVER = "#pragma NO COVER"
 
 class _Ignore:
@@ -451,12 +443,14 @@ def runctx(self, cmd, globals=None, locals=None):
         if globals is None: globals = {}
         if locals is None: locals = {}
         if not self.donothing:
-            _settrace(self.globaltrace)
+            threading.settrace(self.globaltrace)
+            sys.settrace(self.globaltrace)
         try:
             exec(cmd, globals, locals)
         finally:
             if not self.donothing:
-                _unsettrace()
+                sys.settrace(None)
+                threading.settrace(None)
 
     def runfunc(self, func, *args, **kw):
         result = None
diff --git a/Misc/NEWS.d/next/Library/2018-08-21-00-29-01.bpo-34171.6LkWav.rst b/Misc/NEWS.d/next/Library/2018-08-21-00-29-01.bpo-34171.6LkWav.rst
new file mode 100644
index 000000000000..f647b8e3fb4b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-08-21-00-29-01.bpo-34171.6LkWav.rst
@@ -0,0 +1 @@
+Running the :mod:`trace` module no longer creates the ``trace.cover`` file.



More information about the Python-checkins mailing list