From 24001704d81493201dc28623f9bdeb5624daffb7 Mon Sep 17 00:00:00 2001 From: Rich Chiodo Date: Fri, 7 Mar 2025 15:41:52 -0800 Subject: [PATCH] Try making the test_cli tests more robust on Python 3.13 (#1864) --- tests/debugpy/server/test_cli.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/debugpy/server/test_cli.py b/tests/debugpy/server/test_cli.py index a50fd99b..be2960d1 100644 --- a/tests/debugpy/server/test_cli.py +++ b/tests/debugpy/server/test_cli.py @@ -50,7 +50,10 @@ def cli(pyfile): } # Serialize the command line args and the options to stdout - os.write(1, pickle.dumps([sys.argv[1:], options])) + serialized_data = pickle.dumps([sys.argv[1:], options]) + os.write(1, serialized_data) + # Ensure all data is written before process exits + sys.stdout.flush() def parse(args): log.debug("Parsing argv: {0!r}", args) @@ -58,13 +61,24 @@ def cli(pyfile): try: # Run the CLI parser in a subprocess, and capture its output. output = subprocess.check_output( - [sys.executable, "-u", cli_parser.strpath] + args + [sys.executable, "-u", cli_parser.strpath] + args, + stderr=subprocess.PIPE # Capture stderr to help with debugging ) # Deserialize the output and return the parsed argv and options. - argv, options = pickle.loads(output) + try: + argv, options = pickle.loads(output) + except Exception as e: + log.debug("Failed to deserialize output: {0}, Output was: {1!r}", e, output) + raise except subprocess.CalledProcessError as exc: - raise pickle.loads(exc.output) + log.debug("Process exited with code {0}. Output: {1!r}, Error: {2!r}", + exc.returncode, exc.output, exc.stderr) + try: + raise pickle.loads(exc.output) + except Exception as e: + log.debug("Failed to deserialize error output: {0}, Output was: {1!r}", e, exc.output) + raise except EOFError: # We may have just been shutting down. If so, return an empty argv and options. argv, options = [], {}