Skip to content

Commit c406d5c

Browse files
bpo-34171: Prevent creating Lib/trace.cover when run the trace module. (GH-8841)
1 parent 8fdd331 commit c406d5c

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

Lib/test/test_trace.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ def tearDown(self):
387387
def test_cover_files_written_no_highlight(self):
388388
argv = '-m trace --count'.split() + [self.codefile]
389389
status, stdout, stderr = assert_python_ok(*argv)
390+
self.assertEqual(stderr, b'')
391+
tracedir = os.path.dirname(os.path.abspath(trace.__file__))
392+
tracecoverpath = os.path.join(tracedir, "trace.cover")
393+
self.assertFalse(os.path.exists(tracecoverpath))
394+
390395
self.assertTrue(os.path.exists(self.coverfile))
391396
with open(self.coverfile) as f:
392397
self.assertEqual(f.read(),

Lib/trace.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@
6363

6464
import threading
6565

66-
def _settrace(func):
67-
threading.settrace(func)
68-
sys.settrace(func)
69-
70-
def _unsettrace():
71-
sys.settrace(None)
72-
threading.settrace(None)
73-
7466
PRAGMA_NOCOVER = "#pragma NO COVER"
7567

7668
class _Ignore:
@@ -451,12 +443,14 @@ def runctx(self, cmd, globals=None, locals=None):
451443
if globals is None: globals = {}
452444
if locals is None: locals = {}
453445
if not self.donothing:
454-
_settrace(self.globaltrace)
446+
threading.settrace(self.globaltrace)
447+
sys.settrace(self.globaltrace)
455448
try:
456449
exec(cmd, globals, locals)
457450
finally:
458451
if not self.donothing:
459-
_unsettrace()
452+
sys.settrace(None)
453+
threading.settrace(None)
460454

461455
def runfunc(self, func, *args, **kw):
462456
result = None
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Running the :mod:`trace` module no longer creates the ``trace.cover`` file.

0 commit comments

Comments
 (0)