bpo-34171: Prevent creating Lib/trace.cover when run the trace module. (GH-8841)
This commit is contained in:
parent
8fdd331bbf
commit
c406d5cd74
|
@ -387,6 +387,11 @@ class TestCoverageCommandLineOutput(unittest.TestCase):
|
||||||
def test_cover_files_written_no_highlight(self):
|
def test_cover_files_written_no_highlight(self):
|
||||||
argv = '-m trace --count'.split() + [self.codefile]
|
argv = '-m trace --count'.split() + [self.codefile]
|
||||||
status, stdout, stderr = assert_python_ok(*argv)
|
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))
|
self.assertTrue(os.path.exists(self.coverfile))
|
||||||
with open(self.coverfile) as f:
|
with open(self.coverfile) as f:
|
||||||
self.assertEqual(f.read(),
|
self.assertEqual(f.read(),
|
||||||
|
|
14
Lib/trace.py
14
Lib/trace.py
|
@ -63,14 +63,6 @@ from time import monotonic as _time
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
def _settrace(func):
|
|
||||||
threading.settrace(func)
|
|
||||||
sys.settrace(func)
|
|
||||||
|
|
||||||
def _unsettrace():
|
|
||||||
sys.settrace(None)
|
|
||||||
threading.settrace(None)
|
|
||||||
|
|
||||||
PRAGMA_NOCOVER = "#pragma NO COVER"
|
PRAGMA_NOCOVER = "#pragma NO COVER"
|
||||||
|
|
||||||
class _Ignore:
|
class _Ignore:
|
||||||
|
@ -451,12 +443,14 @@ class Trace:
|
||||||
if globals is None: globals = {}
|
if globals is None: globals = {}
|
||||||
if locals is None: locals = {}
|
if locals is None: locals = {}
|
||||||
if not self.donothing:
|
if not self.donothing:
|
||||||
_settrace(self.globaltrace)
|
threading.settrace(self.globaltrace)
|
||||||
|
sys.settrace(self.globaltrace)
|
||||||
try:
|
try:
|
||||||
exec(cmd, globals, locals)
|
exec(cmd, globals, locals)
|
||||||
finally:
|
finally:
|
||||||
if not self.donothing:
|
if not self.donothing:
|
||||||
_unsettrace()
|
sys.settrace(None)
|
||||||
|
threading.settrace(None)
|
||||||
|
|
||||||
def runfunc(self, func, *args, **kw):
|
def runfunc(self, func, *args, **kw):
|
||||||
result = None
|
result = None
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Running the :mod:`trace` module no longer creates the ``trace.cover`` file.
|
Loading…
Reference in New Issue