Skip to content

Commit 759532b

Browse files
committed
update test to check warnings on printing to stderr
1 parent b304829 commit 759532b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tests/test_execute.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def doctree():
2626
apps = []
2727
syspath = sys.path[:]
2828

29-
def doctree(source, config=None):
29+
def doctree(source, config=None, return_warnings=False):
3030
src_dir = tempfile.mkdtemp()
3131
source_trees.append(src_dir)
3232
with open(os.path.join(src_dir, 'conf.py'), 'w') as f:
@@ -35,11 +35,18 @@ def doctree(source, config=None):
3535
f.write('\n' + config)
3636
with open(os.path.join(src_dir, 'index.rst'), 'w') as f:
3737
f.write(source)
38+
warnings = StringIO()
3839
app = SphinxTestApp(srcdir=path(src_dir), status=StringIO(),
39-
warning=StringIO())
40+
warning=warnings)
4041
apps.append(app)
4142
app.build()
42-
return app.env.get_doctree('index')
43+
44+
doctree = app.env.get_doctree("index")
45+
46+
if return_warnings:
47+
return doctree, warnings.getvalue()
48+
else:
49+
return doctree
4350

4451
yield doctree
4552

@@ -217,8 +224,11 @@ def test_stderr(doctree):
217224
import sys
218225
print('hello world', file=sys.stderr)
219226
"""
220-
with pytest.raises(ExtensionError):
221-
tree = doctree(source)
227+
228+
tree, warnings = doctree(source, return_warnings=True)
229+
assert "hello world" in warnings
230+
cell, = tree.traverse(JupyterCellNode)
231+
assert len(cell.children) == 1 # no output
222232

223233
source = """
224234
.. jupyter-execute::

0 commit comments

Comments
 (0)