]> granicus.if.org Git - python/commitdiff
bpo-32852: Fix trace changing sys.argv to tuple. (GH-5692)
authorKyle Altendorf <sda@fstab.net>
Sat, 17 Feb 2018 06:32:37 +0000 (22:32 -0800)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 17 Feb 2018 06:32:37 +0000 (08:32 +0200)
Lib/test/test_trace.py
Lib/trace.py
Misc/NEWS.d/next/Library/2018-02-15-12-04-29.bpo-32852.HDqIxM.rst [new file with mode: 0644]

index 1d87aea5a3d3465131539a3059e90b348c1107c4..e04ca01c4299891bcae99aa45ad780f34186bc23 100644 (file)
@@ -387,5 +387,15 @@ class TestCommandLine(unittest.TestCase):
             status, stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN)
             self.assertIn(b'functions called:', stdout)
 
+    def test_sys_argv_list(self):
+        with open(TESTFN, 'w') as fd:
+            self.addCleanup(unlink, TESTFN)
+            fd.write("import sys\n")
+            fd.write("print(type(sys.argv))\n")
+
+        status, direct_stdout, stderr = assert_python_ok(TESTFN)
+        status, trace_stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN)
+        self.assertIn(direct_stdout.strip(), trace_stdout)
+
 if __name__ == '__main__':
     unittest.main()
index 48a1d1b6a9140233b41bc15c056e83823a155927..ade76166bdd2f559e48e4a59d896bce1637ef75f 100755 (executable)
@@ -705,7 +705,7 @@ def main():
     if opts.filename is None:
         parser.error('filename is missing: required with the main options')
 
-    sys.argv = opts.filename, *opts.arguments
+    sys.argv = [opts.filename, *opts.arguments]
     sys.path[0] = os.path.dirname(opts.filename)
 
     t = Trace(opts.count, opts.trace, countfuncs=opts.listfuncs,
diff --git a/Misc/NEWS.d/next/Library/2018-02-15-12-04-29.bpo-32852.HDqIxM.rst b/Misc/NEWS.d/next/Library/2018-02-15-12-04-29.bpo-32852.HDqIxM.rst
new file mode 100644 (file)
index 0000000..8eabbfa
--- /dev/null
@@ -0,0 +1 @@
+Make sure sys.argv remains as a list when running trace.