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

Display the unexpected warning in tests, if any #865

Merged
merged 2 commits into from
Oct 6, 2021
Merged
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
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