Skip to content

Commit

Permalink
Display the unexpected warning in tests, if any (#865)
Browse files Browse the repository at this point in the history
* Raise on the first unexpected warning

* Ignore the DeprecationWarning about Validator.iter_errors
  • Loading branch information
mwouts authored Oct 6, 2021
1 parent f369062 commit 8aa3d1f
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import unittest.mock as mock
from argparse import ArgumentTypeError
from contextlib import contextmanager
from io import StringIO
from shutil import copyfile
from subprocess import check_call
Expand Down Expand Up @@ -1130,6 +1131,22 @@ def test_sync_script_dotdot_folder_564(tmpdir):
jupytext(["--sync", str(nb_file)])


@contextmanager
def no_warning():
with pytest.warns(None) as warnings:
yield

# There should be no warning
for record in warnings:
# Temporary exception for for this one, see #865
if (
"Passing a schema to Validator.iter_errors is deprecated "
"and will be removed in a future release" in str(record.message)
):
continue
raise RuntimeError(record)


def test_jupytext_to_file_emits_a_warning(tmpdir):
"""The user may type
jupytext notebook.ipynb --to script.py
Expand All @@ -1141,11 +1158,9 @@ def test_jupytext_to_file_emits_a_warning(tmpdir):
nb_file = tmpdir.join("notebook.ipynb")
write(new_notebook(), str(nb_file))

with pytest.warns(None) as record:
with no_warning():
jupytext(["notebook.ipynb", "-o", "script.py"])

assert len(record) == 0

with pytest.warns(UserWarning, match="Maybe you want to use the '-o' option"):
jupytext(["notebook.ipynb", "--to", "script.py"])

Expand All @@ -1164,11 +1179,9 @@ def test_jupytext_set_formats_file_gives_an_informative_error(tmpdir, cwd_tmpdir
nb_file = tmpdir.join("notebook.ipynb")
md_file.write("Some text")

with pytest.warns(None) as warnings:
with no_warning():
jupytext(["--sync", "notebook.md"])

assert not warnings

assert py_file.exists()
assert nb_file.exists()

Expand Down

0 comments on commit 8aa3d1f

Please sign in to comment.