Skip to content

Commit c1a47d1

Browse files
committed
Log stdout and stderr for failed examples.
1 parent bb58d77 commit c1a47d1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

test/test_examples.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Copyright Contributors to the Pyro project.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
import logging
45
import os
5-
from subprocess import check_call
6+
from subprocess import check_output, CalledProcessError, PIPE
67
import sys
78

89
import pytest
@@ -80,9 +81,15 @@
8081
@pytest.mark.parametrize("example", EXAMPLES)
8182
@pytest.mark.filterwarnings("ignore:There are not enough devices:UserWarning")
8283
@pytest.mark.filterwarnings("ignore:Higgs is a 2.6 GB dataset:UserWarning")
83-
def test_cpu(example):
84+
def test_cpu(request: pytest.FixtureRequest, example):
8485
print("Running:\npython examples/{}".format(example))
8586
example = example.split()
8687
filename, args = example[0], example[1:]
8788
filename = os.path.join(EXAMPLES_DIR, filename)
88-
check_call([sys.executable, filename] + args)
89+
try:
90+
check_output([sys.executable, filename] + args, text=True, stderr=PIPE)
91+
except CalledProcessError as ex:
92+
logger = logging.getLogger(request.node.name)
93+
logger.error("stdout:\n%s", ex.stdout)
94+
logger.error("stdout:\n%s", ex.stderr)
95+
raise

0 commit comments

Comments
 (0)