From 8866f80d9d9155f9f10ab25ec9f543d0006b8089 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Thu, 9 Dec 2021 23:33:59 +0100 Subject: [PATCH 01/12] Filter expected (Jupytext) warnings in tests --- tests/test_cli.py | 6 ++++++ tests/test_cm_config.py | 4 ++++ tests/test_pre_commit_scripts.py | 1 + 3 files changed, 11 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index c03cdd4a5..0c7d6eccd 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -703,6 +703,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([]) @@ -722,6 +723,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" diff --git a/tests/test_cm_config.py b/tests/test_cm_config.py index c81d752c4..0577a0976 100644 --- a/tests/test_cm_config.py +++ b/tests/test_cm_config.py @@ -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 arguments " + r"to super\(JupytextConfiguration\).__init__" +) def test_incorrect_config_message(tmpdir, cfg_file, cfg_text): cm = jupytext.TextFileContentsManager() cm.root_dir = str(tmpdir) diff --git a/tests/test_pre_commit_scripts.py b/tests/test_pre_commit_scripts.py index ce545be60..b70514fc1 100644 --- a/tests/test_pre_commit_scripts.py +++ b/tests/test_pre_commit_scripts.py @@ -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")) From 47e1718a2a12e5500e30cd594121caf3ec247092 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Thu, 9 Dec 2021 23:56:40 +0100 Subject: [PATCH 02/12] Use 'with' to open test files --- tests/test_cli.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 0c7d6eccd..8da568d45 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -794,9 +794,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 From d211662957d84a7628de07b297f20885b59f308e Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Thu, 9 Dec 2021 23:57:16 +0100 Subject: [PATCH 03/12] Turn all warnings into errors (excepted few known ones) --- pyproject.toml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 87eef4f66..24e3b396d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,15 @@ [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 = [ + # use single quote to denote raw strings in toml + "error", + '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. Date: Fri, 10 Dec 2021 00:16:58 +0100 Subject: [PATCH 04/12] Filter a typo in the warning (Python 3.6) --- tests/test_cm_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cm_config.py b/tests/test_cm_config.py index 0577a0976..574815fff 100644 --- a/tests/test_cm_config.py +++ b/tests/test_cm_config.py @@ -88,7 +88,7 @@ def test_pairing_through_config_leaves_ipynb_unmodified(tmpdir): ], ) @pytest.mark.filterwarnings( - r"ignore:Passing unrecognized arguments " + r"ignore:Passing unrecog(i)nized arguments " r"to super\(JupytextConfiguration\).__init__" ) def test_incorrect_config_message(tmpdir, cfg_file, cfg_text): From abb6991a411812b5840ddf7cb4ac984fc0c064a6 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Fri, 10 Dec 2021 00:17:11 +0100 Subject: [PATCH 05/12] Filter more expected warnings --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 24e3b396d..be98bf990 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,9 @@ filterwarnings = [ "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. Date: Fri, 10 Dec 2021 00:43:10 +0100 Subject: [PATCH 06/12] Update CHANGELOG.md --- docs/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b3505f831..5631a58a4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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)) From 156ead198583674b8160bf69e13df2ffd1ed3f1e Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Fri, 10 Dec 2021 01:05:01 +0100 Subject: [PATCH 07/12] Next iteration on warning filters --- pyproject.toml | 2 +- tests/test_cm_config.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index be98bf990..d0667678a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ filterwarnings = [ "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. Date: Fri, 10 Dec 2021 01:20:23 +0100 Subject: [PATCH 08/12] Last attempt to filter warnings (Python 3.7) --- tests/test_cli.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 8da568d45..e79446593 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -687,6 +687,10 @@ def test_set_kernel_works_with_pipes_326(capsys): @skip_on_windows +@pytest.mark.filterwarnings( + "ignore:unclosed context Date: Fri, 10 Dec 2021 01:21:06 +0100 Subject: [PATCH 09/12] Add a comment on the "error" filter --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d0667678a..3935ec138 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,8 +3,9 @@ requires = ["jupyter_packaging~=0.7.9", "jupyterlab>=3.0.0,==3.*", "setuptools>= build-backend = "setuptools.build_meta" [tool.pytest.ini_options] filterwarnings = [ - # use single quote to denote raw strings in toml + # 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", From e8706a736f4063669fee8e04b3ea2fe13eaa9ce0 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Fri, 10 Dec 2021 01:38:21 +0100 Subject: [PATCH 10/12] Ignore all warnings in test_utf8_out_331 (hard to catch since they happen in "err") --- tests/test_cli.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index e79446593..fcaf9554c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -687,10 +687,7 @@ def test_set_kernel_works_with_pipes_326(capsys): @skip_on_windows -@pytest.mark.filterwarnings( - "ignore:unclosed context Date: Fri, 10 Dec 2021 01:38:49 +0100 Subject: [PATCH 11/12] Catch warning on Conda/Python 3.7/Windows --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3935ec138..907ad6dcf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,5 +15,7 @@ filterwarnings = [ # in test_cli_expect_errors and two others 'ignore:Exception ignored in. Date: Fri, 10 Dec 2021 11:58:08 +0100 Subject: [PATCH 12/12] That test requires jupytext installed --- tests/test_cli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index fcaf9554c..68e243519 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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)))