]> granicus.if.org Git - python/commitdiff
bpo-32852: Fix trace changing sys.argv to tuple. (GH-5692)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 17 Feb 2018 07:14:41 +0000 (23:14 -0800)
committerGitHub <noreply@github.com>
Sat, 17 Feb 2018 07:14:41 +0000 (23:14 -0800)
(cherry picked from commit 9f4223261fd129ad7b9a09b2b0d625d1bb90b22b)

Co-authored-by: Kyle Altendorf <sda@fstab.net>
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 ae154615fa3af4a8f093b761c384e3a1ba1f86ee..9ba9486bd024752c03c2077eeffde9273a6497e8 100755 (executable)
@@ -710,7 +710,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.