]> granicus.if.org Git - python/commitdiff
bpo-34171: Prevent creating Lib/trace.cover when run the trace module. (GH-8841)
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 25 Aug 2018 07:27:55 +0000 (10:27 +0300)
committerGitHub <noreply@github.com>
Sat, 25 Aug 2018 07:27:55 +0000 (10:27 +0300)
Lib/test/test_trace.py
Lib/trace.py
Misc/NEWS.d/next/Library/2018-08-21-00-29-01.bpo-34171.6LkWav.rst [new file with mode: 0644]

index dc9b3fa7b6af8c33fd0698192ab457144f8e638e..3b335ca42f90eebaaa1f035c708c8edc4dac99a2 100644 (file)
@@ -387,6 +387,11 @@ class TestCoverageCommandLineOutput(unittest.TestCase):
     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(),
index 16c3494689dd9ce44a4f985686532ed2eff349a4..86b2101763bfa469aba2aaf13d2b816850a4464f 100755 (executable)
@@ -63,14 +63,6 @@ from time import monotonic as _time
 
 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 @@ class Trace:
         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 (file)
index 0000000..f647b8e
--- /dev/null
@@ -0,0 +1 @@
+Running the :mod:`trace` module no longer creates the ``trace.cover`` file.