forked from goodboy/tractor
1
0
Fork 0

Always print any std streams to console in docs examples tests

macos_in_ci
Tyler Goodlet 2022-11-06 16:42:13 -05:00
parent 64819b2acb
commit e12def51a8
1 changed files with 29 additions and 20 deletions

View File

@ -93,14 +93,16 @@ def run_example_in_subproc(loglevel, testdir, arb_addr):
ids=lambda t: t[1], ids=lambda t: t[1],
) )
def test_example(run_example_in_subproc, example_script): def test_example(run_example_in_subproc, example_script):
"""Load and run scripts from this repo's ``examples/`` dir as a user '''
Load and run scripts from this repo's ``examples/`` dir as a user
would copy and pasing them into their editor. would copy and pasing them into their editor.
On windows a little more "finessing" is done to make On windows a little more "finessing" is done to make
``multiprocessing`` play nice: we copy the ``__main__.py`` into the ``multiprocessing`` play nice: we copy the ``__main__.py`` into the
test directory and invoke the script as a module with ``python -m test directory and invoke the script as a module with ``python -m
test_example``. test_example``.
"""
'''
ex_file = os.path.join(*example_script) ex_file = os.path.join(*example_script)
if 'rpc_bidir_streaming' in ex_file and sys.version_info < (3, 9): if 'rpc_bidir_streaming' in ex_file and sys.version_info < (3, 9):
@ -110,25 +112,32 @@ def test_example(run_example_in_subproc, example_script):
code = ex.read() code = ex.read()
with run_example_in_subproc(code) as proc: with run_example_in_subproc(code) as proc:
proc.wait() try:
err, _ = proc.stderr.read(), proc.stdout.read() proc.wait(timeout=5)
# print(f'STDERR: {err}') finally:
# print(f'STDOUT: {out}') err = proc.stderr.read()
# if we get some gnarly output let's aggregate and raise
if err:
errmsg = err.decode() errmsg = err.decode()
errlines = errmsg.splitlines() out = proc.stdout.read()
last_error = errlines[-1] outmsg = out.decode()
if (
'Error' in last_error
# XXX: currently we print this to console, but maybe if out:
# shouldn't eventually once we figure out what's print(f'STDOUT: {out.decode()}')
# a better way to be explicit about aio side
# cancels? # if we get some gnarly output let's aggregate and raise
and 'asyncio.exceptions.CancelledError' not in last_error if err:
): print(f'STDERR:\n{errmsg}')
raise Exception(errmsg) errmsg = err.decode()
errlines = errmsg.splitlines()
last_error = errlines[-1]
if (
'Error' in last_error
# XXX: currently we print this to console, but maybe
# shouldn't eventually once we figure out what's
# a better way to be explicit about aio side
# cancels?
and 'asyncio.exceptions.CancelledError' not in last_error
):
raise Exception(errmsg)
assert proc.returncode == 0 assert proc.returncode == 0