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

Filter known warnings in tests and raise on others #893

Merged
merged 12 commits into from
Dec 10, 2021
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Jupytext ChangeLog
1.13.4-dev (2021-12-??)
-----------------------

**Changed**
- The test suite turns warnings into errors, after filtering the warnings that don't belong to Jupytext ([#823](https://github.com/mwouts/jupytext/issues/823))

**Fixed**
- The parsing of notebooks that don't have a YAML header (like `docs/formats.md`) was improved.
- The test suite works with `pytest-randomly` ([#838](https://github.com/mwouts/jupytext/issues/838))
Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
[build-system]
requires = ["jupyter_packaging~=0.7.9", "jupyterlab>=3.0.0,==3.*", "setuptools>=40.8.0", "wheel"]
build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
filterwarnings = [
# Uncomment this "error" to turn all unfiltered warnings into errors
"error",
# use single quote to denote raw strings in toml
'ignore:Passing unrecognized arguments to super\(KernelSpec\).__init__:DeprecationWarning',
# In many tests
"ignore:Passing a schema to Validator.iter_errors is deprecated and will be removed in a future release:DeprecationWarning",
# in test_utf8_out_331 and two others
'ignore:Exception ignored in. <function Context.__del__:pytest.PytestUnraisableExceptionWarning',
'ignore:.*contextfilter.* renamed to .*pass_context:DeprecationWarning',
# in test_cli_expect_errors and two others
'ignore:Exception ignored in. <socket.socket:pytest.PytestUnraisableExceptionWarning',
# test_config_jupytext_jupyter_fs_meta_manager
'ignore:The alias `_\(\)` will be deprecated. Use `_i18n\(\)` instead.:FutureWarning',
# Conda/Python 3.7/Windows - ImportError while loading conftest
"ignore:the imp module is deprecated in favour of importlib:DeprecationWarning"
]
17 changes: 14 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_convert_single_file_in_place(nb_file, tmpdir):
compare_notebooks(nb2, nb1)


@requires_jupytext_installed
def test_convert_single_file_in_place_m(tmpdir):
nb_file = list_notebooks("ipynb_py")[0]
nb_org = str(tmpdir.join(os.path.basename(nb_file)))
Expand Down Expand Up @@ -687,6 +688,7 @@ def test_set_kernel_works_with_pipes_326(capsys):


@skip_on_windows
@pytest.mark.filterwarnings("ignore")
def test_utf8_out_331(capsys, caplog):
py = u"from IPython.core.display import HTML; HTML(u'\xd7')"

Expand All @@ -703,6 +705,7 @@ def test_utf8_out_331(capsys, caplog):


@requires_jupytext_installed
@pytest.mark.filterwarnings("ignore:The --pre-commit argument is deprecated")
def test_cli_expect_errors(tmp_ipynb):
with pytest.raises(ValueError):
jupytext([])
Expand All @@ -722,6 +725,11 @@ def test_cli_expect_errors(tmp_ipynb):
system("jupytext", ["notebook.ipynb", "--from", "py:percent", "--to", "md"])


@pytest.mark.filterwarnings(
"ignore:You have passed a file name to the '--to' option, "
"when a format description was expected. "
"Maybe you want to use the '-o' option instead?"
)
def test_format_prefix_suffix(tmpdir, cwd_tmpdir):
os.makedirs("notebooks")
tmp_ipynb = "notebooks/notebook_name.ipynb"
Expand Down Expand Up @@ -788,9 +796,12 @@ def test_cli_sync_file_with_suffix(tmpdir, cwd_tmpdir):
jupytext(["--sync", tmp_lgt_py])
jupytext(["--sync", tmp_ipynb])

assert open(tmp_lgt_py).read().splitlines()[-2:] == ["", "1+1"]
assert open(tmp_pct_py).read().splitlines()[-3:] == ["", "# %%", "1+1"]
assert open(tmp_rmd).read().splitlines()[-4:] == ["", "```{python}", "1+1", "```"]
with open(tmp_lgt_py) as fp:
assert fp.read().splitlines()[-2:] == ["", "1+1"]
with open(tmp_pct_py) as fp:
fp.read().splitlines()[-3:] == ["", "# %%", "1+1"]
with open(tmp_rmd) as fp:
fp.read().splitlines()[-4:] == ["", "```{python}", "1+1", "```"]


@requires_sphinx_gallery
Expand Down
4 changes: 4 additions & 0 deletions tests/test_cm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def test_pairing_through_config_leaves_ipynb_unmodified(tmpdir):
(".jupytext.py", "c.hide_notebook_metadata = true"),
],
)
@pytest.mark.filterwarnings(
r"ignore:Passing (unrecognized|unrecoginized) arguments "
r"to super\(JupytextConfiguration\).__init__"
)
def test_incorrect_config_message(tmpdir, cfg_file, cfg_text):
cm = jupytext.TextFileContentsManager()
cm.root_dir = str(tmpdir)
Expand Down
1 change: 1 addition & 0 deletions tests/test_pre_commit_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def test_pre_commit_hook_sync_black_flake8(tmpdir, nb_file):
git("commit", "-m", "created")


@pytest.mark.filterwarnings("ignore:The --pre-commit argument is deprecated")
def test_manual_call_of_pre_commit_hook(tmpdir):
tmp_ipynb = str(tmpdir.join("notebook.ipynb"))
tmp_py = str(tmpdir.join("notebook.py"))
Expand Down