Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch timeout messages both in the logs and in stderr #489 #537

Merged
merged 1 commit into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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