Skip to content

Commit

Permalink
Catch timeout messages both in the logs and in stderr #489
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jun 6, 2020
1 parent 6505db0 commit b677ea2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
3 changes: 3 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ def test_utf8_out_331(capsys, caplog):
pytest.skip(caplog.text) # Issue 489

out, err = capsys.readouterr()
if "Timeout" in err:
pytest.skip(err) # Issue 489

assert err == ""
nb = reads(out, "ipynb")
assert len(nb.cells) == 1
Expand Down
40 changes: 22 additions & 18 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
from jupytext.cli import jupytext


def skip_if_timeout(caplog, capsys):
"""Skip the test if a timeout occurs when executing the notebook. See Issue 489"""
if "Timeout" in caplog.text:
pytest.skip(caplog.text)

_, err = capsys.readouterr()
if "Timeout" in err:
pytest.skip(err)


@requires_nbconvert
def test_pipe_nbconvert_execute(tmpdir, caplog):
def test_pipe_nbconvert_execute(tmpdir, caplog, capsys):
tmp_ipynb = str(tmpdir.join("notebook.ipynb"))
tmp_py = str(tmpdir.join("notebook.py"))

Expand All @@ -26,16 +36,15 @@ def test_pipe_nbconvert_execute(tmpdir, caplog):
"jupyter nbconvert --stdin --stdout --to notebook --execute",
]
)
if "Timeout" in caplog.text:
pytest.skip(caplog.text) # Issue 489
skip_if_timeout(caplog, capsys)

nb = read(tmp_ipynb)
assert len(nb.cells) == 1
assert nb.cells[0].outputs[0]["data"] == {"text/plain": "3"}


@requires_nbconvert
def test_pipe_nbconvert_execute_sync(tmpdir, caplog):
def test_pipe_nbconvert_execute_sync(tmpdir, caplog, capsys):
tmp_ipynb = str(tmpdir.join("notebook.ipynb"))
tmp_py = str(tmpdir.join("notebook.py"))

Expand All @@ -57,16 +66,15 @@ def test_pipe_nbconvert_execute_sync(tmpdir, caplog):
"jupyter nbconvert --stdin --stdout --to notebook --execute",
]
)
if "Timeout" in caplog.text:
pytest.skip(caplog.text) # Issue 489
skip_if_timeout(caplog, capsys)

nb = read(tmp_ipynb)
assert len(nb.cells) == 1
assert nb.cells[0].outputs[0]["data"] == {"text/plain": "3"}


@requires_nbconvert
def test_execute(tmpdir, caplog):
def test_execute(tmpdir, caplog, capsys):
tmp_ipynb = str(tmpdir.join("notebook.ipynb"))
tmp_py = str(tmpdir.join("notebook.py"))

Expand All @@ -77,8 +85,7 @@ def test_execute(tmpdir, caplog):
)

jupytext(args=[tmp_py, "--to", "ipynb", "--execute"])
if "Timeout" in caplog.text:
pytest.skip(caplog.text) # Issue 489
skip_if_timeout(caplog, capsys)

nb = read(tmp_ipynb)
assert len(nb.cells) == 1
Expand Down Expand Up @@ -127,7 +134,7 @@ def test_execute_readme_not_ok(tmpdir):


@requires_nbconvert
def test_execute_sync(tmpdir, caplog):
def test_execute_sync(tmpdir, caplog, capsys):
tmp_ipynb = str(tmpdir.join("notebook.ipynb"))
tmp_py = str(tmpdir.join("notebook.py"))

Expand All @@ -138,8 +145,7 @@ def test_execute_sync(tmpdir, caplog):
)

jupytext(args=[tmp_py, "--set-formats", "py,ipynb", "--sync", "--execute"])
if "Timeout" in caplog.text:
pytest.skip(caplog.text) # Issue 489
skip_if_timeout(caplog, capsys)

nb = read(tmp_ipynb)
assert len(nb.cells) == 1
Expand All @@ -148,7 +154,7 @@ def test_execute_sync(tmpdir, caplog):

@requires_nbconvert
@requires_ir_kernel
def test_execute_r(tmpdir, caplog): # pragma: no cover
def test_execute_r(tmpdir, caplog, capsys): # pragma: no cover
tmp_ipynb = str(tmpdir.join("notebook.ipynb"))
tmp_md = str(tmpdir.join("notebook.md"))

Expand All @@ -161,16 +167,15 @@ def test_execute_r(tmpdir, caplog): # pragma: no cover
)

jupytext(args=[tmp_md, "--to", "ipynb", "--execute"])
if "Timeout" in caplog.text:
pytest.skip(caplog.text) # Issue 489
skip_if_timeout(caplog, capsys)

nb = read(tmp_ipynb)
assert len(nb.cells) == 1
assert nb.cells[0].outputs[0]["data"]["text/markdown"] == "6"


@requires_nbconvert
def test_execute_in_subfolder(tmpdir, caplog):
def test_execute_in_subfolder(tmpdir, caplog, capsys):
tmpdir.mkdir("subfolder")

tmp_csv = str(tmpdir.join("subfolder", "inputs.csv"))
Expand All @@ -192,8 +197,7 @@ def test_execute_in_subfolder(tmpdir, caplog):
)

jupytext(args=[tmp_py, "--to", "ipynb", "--execute"])
if "Timeout" in caplog.text:
pytest.skip(caplog.text) # Issue 489
skip_if_timeout(caplog, capsys)

nb = read(tmp_ipynb)
assert len(nb.cells) == 3
Expand Down

0 comments on commit b677ea2

Please sign in to comment.