Skip to content

Commit

Permalink
Merge pull request #113 from xsnippet/logging
Browse files Browse the repository at this point in the history
Capture the logs of the xsnippet-api process started in tests
  • Loading branch information
malor committed Jan 24, 2021
2 parents face436 + 9955740 commit a290af9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/test_gabbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import socket
import subprocess
import sys
import tempfile
import time

import gabbi.driver
Expand Down Expand Up @@ -47,7 +48,16 @@ def start_fixture(self):
environ = os.environ.copy()
environ.update(self.environ)

self.process = subprocess.Popen(self._launch_command, env=environ)
# capture stdout/stderr of xsnippet-api process to a temporary file.
# Alternatively, we could either connect the child process to our
# file descriptors (in which case, log messages from both processes
# would interleave), or connect them to a pipe (this is also not great,
# because the child process can easily fill up the pipe buffer if we do
# not regularly read from it in a separate thread).
self.application_log = tempfile.TemporaryFile()
self.process = subprocess.Popen(self._launch_command, env=environ,
stdout=self.application_log,
stderr=subprocess.STDOUT)
_wait_for_socket(XSNIPPET_API_HOST, XSNIPPET_API_PORT, self._launch_timeout)

def stop_fixture(self):
Expand All @@ -60,6 +70,11 @@ def stop_fixture(self):
except TimeoutError:
self.process.kill()
finally:
self.application_log.seek(0)
print('xsnippet-api log:')
print(self.application_log.read().decode())
self.application_log.close()

self.process = None


Expand Down

0 comments on commit a290af9

Please sign in to comment.