From 0e1f615601b58c4c77fd352991acac8844c68989 Mon Sep 17 00:00:00 2001 From: Max Marrone <max@marrone.nyc> Date: Wed, 13 Apr 2022 10:01:11 -0400 Subject: [PATCH] test(robot-server): Pass along server subprocess's logs to pytest (#9947) --- robot-server/tests/conftest.py | 7 +++++-- robot-server/tests/integration/dev_server.py | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/robot-server/tests/conftest.py b/robot-server/tests/conftest.py index 4105cf765e1..69e9c5576b3 100644 --- a/robot-server/tests/conftest.py +++ b/robot-server/tests/conftest.py @@ -141,8 +141,11 @@ def run_server( "OT_ROBOT_SERVER_DOT_ENV_PATH": "dev.env", "OT_API_CONFIG_DIR": server_temp_directory, }, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stdin=subprocess.DEVNULL, + # The server will log to its stdout or stderr. + # Let it inherit our stdout and stderr so pytest captures its logs. + stdout=None, + stderr=None, ) as proc: # Wait for a bit to get started by polling /health from requests.exceptions import ConnectionError diff --git a/robot-server/tests/integration/dev_server.py b/robot-server/tests/integration/dev_server.py index 547d5c442ef..3ad191eedc4 100644 --- a/robot-server/tests/integration/dev_server.py +++ b/robot-server/tests/integration/dev_server.py @@ -54,12 +54,14 @@ def start(self) -> None: "OT_API_CONFIG_DIR": self.server_temp_directory, "OT_ROBOT_SERVER_persistence_directory": self.persistence_directory, }, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stdin=subprocess.DEVNULL, + # The server will log to its stdout or stderr. + # Let it inherit our stdout and stderr so pytest captures its logs. + stdout=None, + stderr=None, ) def stop(self) -> None: """Stop the robot server.""" self.proc.send_signal(signal.SIGTERM) - # This calls proc.wait() and does cleanup on stdin, stdout and stderr. - self.proc.__exit__(None, None, None) + self.proc.wait()