Repository: mwouts/jupytext (language: python)

Issue:
Filter out expected warnings in pytest
When one runs `pytest` on this project, a series of warnings are displayed.
Since most of this warnings are expected, we should find a way to filter them out.

Below is a sample log provided by @kloczek in [this comment](https://github.com/mwouts/jupytext/issues/814#issuecomment-880121455):
```
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-jupytext-1.11.3-2.2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-jupytext-1.11.3-2.2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.11, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, httpbin-1.0.0, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, freezegun-0.4.2, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, asyncio-0.15.1, toolbox-0.5, xprocess-0.17.1, aiohttp-0.3.0, checkdocs-2.7.0, mock-3.6.1, rerunfailures-9.1.1, requests-mock-1.9.3, cov-2.12.1, pyfakefs-4.5.0, flaky-3.7.0, hypothesis-6.14.0, benchmark-3.4.1, xdist-2.3.0, pylama-7.7.1, datadir-1.3.1, regressions-2.2.0, cases-3.6.3, Faker-8.10.0
collected 2584 items

. .                                                                                                                                                                  [  0%]
tests/test_active_cells.py ............................                                                                                                              [  1%]
tests/test_auto_ext.py .............................................................x.s.......................                                                       [  4%]
tests/test_black.py ...s........                                                                                                                                     [  4%]
tests/test_cell_id.py .                                                                                                                                              [  4%]
tests/test_cell_metadata.py ............................................................                                                                             [  7%]
tests/test_cells.py ...............                                                                                                                                  [  7%]
tests/test_changelog.py ...                                                                                                                                          [  8%]
tests/test_cli.py .................................................................................................................................................. [ 13%]
........................................................sssssssssssssss............................................................................................. [ 20%]
s........................................................................ssssssss...s....s................                                                           [ 24%]
tests/test_cli_config.py ...........                                                                                                                                 [ 24%]
tests/test_cm_config.py ............                                                                                                                                 [ 25%]
tests/test_combine.py ..................................................                                                                                             [ 26%]
tests/test_compare.py .....................                                                                                                                          [ 27%]
tests/test_config.py .................                                                                                                                               [ 28%]
tests/test_contentsmanager.py ...................................................sssssssssssssssss.................................................................. [ 33%]
.................................................................................................................................................................... [ 39%]
................................................................................................................................s................................... [ 46%]
..ss                                                                                                                                                                 [ 46%]
tests/test_custom_cell_magics.py .                                                                                                                                   [ 46%]
tests/test_doxygen.py ..........                                                                                                                                     [ 46%]
tests/test_escape_magics.py ................................................................................                                                         [ 50%]
tests/test_execute.py ......s.                                                                                                                                       [ 50%]
tests/test_formats.py ......................s..                                                                                                                      [ 51%]
tests/test_header.py ..........                                                                                                                                      [ 51%]
tests/test_hide_remove_input_outputs_rmarkdown.py ........                                                                                                           [ 51%]
tests/test_ipynb_to_R.py ....                                                                                                                                        [ 52%]
tests/test_ipynb_to_myst.py .......ss...                                                                                                                             [ 52%]
tests/test_ipynb_to_py.py ....................                                                                                                                       [ 53%]
tests/test_ipynb_to_rmd.py ........................                                                                                                                  [ 54%]
tests/test_isort.py .                                                                                                                                                [ 54%]
tests/test_jupytext_errors.py ..                                                                                                                                     [ 54%]
tests/test_jupytext_nbconvert_round_trip.py .......................                                                                                                  [ 55%]
tests/test_jupytext_read.py ..                                                                                                                                       [ 55%]
tests/test_knitr_spin.py .                                                                                                                                           [ 55%]
tests/test_load_multiple.py ..                                                                                                                                       [ 55%]
tests/test_markdown_in_code_cells.py ....                                                                                                                            [ 55%]
tests/test_metadata_filter.py .................                                                                                                                      [ 56%]
tests/test_metadata_filters_from_config.py .                                                                                                                         [ 56%]
tests/test_mirror.py ............................................................................................................................................... [ 61%]
..................................................................................sssssssssssssssss..........................................sssssssssss............ [ 68%]
...ss...................................................................................................                                                             [ 72%]
tests/test_nbformat_version.py .......                                                                                                                               [ 72%]
tests/test_paired_paths.py ......................                                                                                                                    [ 73%]
tests/test_pep8.py ...................................................................................................................                               [ 77%]
tests/test_pre_commit_0_ipynb_to_py.py s                                                                                                                             [ 77%]
tests/test_pre_commit_1_sync.py s                                                                                                                                    [ 77%]
tests/test_pre_commit_2_sync_nbstripout.py s                                                                                                                         [ 77%]
tests/test_pre_commit_3_sync_black_nbstripout.py s                                                                                                                   [ 78%]
tests/test_pre_commit_4_sync_execute.py s                                                                                                                            [ 78%]
tests/test_pre_commit_5_reformat_markdown.py s                                                                                                                       [ 78%]
tests/test_pre_commit_mode.py ............                                                                                                                           [ 78%]
tests/test_pre_commit_scripts.py .......s                                                                                                                            [ 78%]
tests/test_preserve_empty_cells.py .......                                                                                                                           [ 79%]
tests/test_pytest.py ..                                                                                                                                              [ 79%]
tests/test_read_all_py.py ..........................................................................................................                                 [ 83%]
tests/test_read_dotnet_try_markdown.py ...                                                                                                                           [ 83%]
tests/test_read_folding_markers.py .....                                                                                                                             [ 83%]
tests/test_read_incomplete_rmd.py ...                                                                                                                                [ 83%]
tests/test_read_simple_R.py ............                                                                                                                             [ 84%]
tests/test_read_simple_clojure.py .                                                                                                                                  [ 84%]
tests/test_read_simple_csharp.py .......                                                                                                                             [ 84%]
tests/test_read_simple_groovy.py .                                                                                                                                   [ 84%]
tests/test_read_simple_hydrogen.py .......                                                                                                                           [ 84%]
tests/test_read_simple_ipynb.py .                                                                                                                                    [ 84%]
tests/test_read_simple_java.py .                                                                                                                                     [ 84%]
tests/test_read_simple_julia.py .                                                                                                                                    [ 84%]
tests/test_read_simple_markdown.py ....................................                                                                                              [ 86%]
tests/test_read_simple_matlab.py ..                                                                                                                                  [ 86%]
tests/test_read_simple_nomarker.py ..                                                                                                                                [ 86%]
tests/test_read_simple_pandoc.py sssss                                                                                                                               [ 86%]
tests/test_read_simple_percent.py ......................                                                                                                             [ 87%]
tests/test_read_simple_python.py ................................................                                                                                    [ 89%]
tests/test_read_simple_rmd.py .........                                                                                                                              [ 89%]
tests/test_read_simple_rust.py ...                                                                                                                                   [ 89%]
tests/test_read_simple_scheme.py .                                                                                                                                   [ 89%]
tests/test_read_simple_sphinx.py ...                                                                                                                                 [ 90%]
tests/test_read_write_functions.py .....                                                                                                                             [ 90%]
tests/test_rmd_to_ipynb.py ......                                                                                                                                    [ 90%]
tests/test_save_multiple.py .....................................................                                                                                    [ 92%]
tests/test_stringparser.py ....                                                                                                                                      [ 92%]
tests/test_trust_notebook.py ................................................                                                                                        [ 94%]
tests/test_unicode.py ...............................                                                                                                                [ 95%]
tests/test_using_cli.py .                                                                                                                                            [ 95%]
tests/test_write_does_not_modify_notebook.py ..............................................................................................................          [100%]

============================================================================= warnings summary =============================================================================
jupytext/cell_reader.py:20
  /home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3/jupytext/cell_reader.py:20: UserWarning: Sphinx Gallery in version 0.8.2 is not supported by Jupytext. Please use sphinx-gallery<=0.7.0 instead. If that is an issue, feel free to report it at https://github.com/mwouts/jupytext/issues, or even better, prepare a PR to handle the new signature of sphinx_gallery.notebook.rst2md.
    warnings.warn(

tests/test_cli.py::test_utf8_out_331
  /usr/lib/python3.8/site-packages/nbconvert/exporters/html.py:110: DeprecationWarning: 'contextfilter' is renamed to 'pass_context', the old name will be removed in Jinja 3.1.
    def markdown2html(self, context, source):

tests/test_cli.py::test_cli_expect_errors
  /home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3/jupytext/cli.py:332: DeprecationWarning: The --pre-commit argument is deprecated. Please consider switching to the pre-commit.com framework (let us know at https://github.com/mwouts/jupytext/issues if that is an issue for you)
    warnings.warn(

tests/test_cli.py::test_format_prefix_suffix
  [warning] 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?

tests/test_cm_config.py::test_incorrect_config_message[jupytext.toml-not_a_jupytext_option = true]
tests/test_cm_config.py::test_incorrect_config_message[jupytext.toml-not_a_jupytext_option = true]
tests/test_cm_config.py::test_incorrect_config_message[.jupytext.py-c.not_a_jupytext_option = True]
tests/test_cm_config.py::test_incorrect_config_message[.jupytext.py-c.not_a_jupytext_option = True]
  [warning] Passing unrecognized arguments to super(JupytextConfiguration).__init__(not_a_jupytext_option=True).
  object.__init__() takes exactly one argument (the instance to initialize)
  This is deprecated in traitlets 4.2.This error will be raised in a future release of traitlets.

tests/test_contentsmanager.py: 48 warnings
  [warning] GObject.GError is deprecated; use GLib.GError instead

tests/test_pre_commit_scripts.py::test_manual_call_of_pre_commit_hook
  [warning] The --pre-commit argument is deprecated. Please consider switching to the pre-commit.com framework (let us know at https://github.com/mwouts/jupytext/issues if that is an issue for you)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================================= short test summary info ==========================================================================
SKIPPED [1] tests/test_auto_ext.py:36: No file_extension in language_info
SKIPPED [1] tests/test_black.py:67: autopep8 not found
SKIPPED [15] tests/test_cli.py:557: pandoc>=2.11 is not available
SKIPPED [1] tests/test_cli.py:795: sphinx_gallery is not available
SKIPPED [3] tests/test_cli.py:991: pandoc>=2.11 is not available
SKIPPED [5] tests/test_cli.py:1005: pandoc>=2.11 is not available
SKIPPED [1] tests/test_cli.py:1075: pandoc>=2.11 is not available
SKIPPED [1] tests/test_cli.py:1188: Please run 'python -m ipykernel install --name python_kernel --user'
SKIPPED [17] tests/test_contentsmanager.py:180: pandoc>=2.11 is not available
SKIPPED [1] tests/test_contentsmanager.py:1188: sphinx_gallery is not available
SKIPPED [2] tests/test_contentsmanager.py:1765: jupyterfs is not available
SKIPPED [1] tests/test_execute.py:150: irkernel is not installed
SKIPPED [1] tests/test_formats.py:324: pandoc>=2.11 is not available
SKIPPED [1] tests/test_ipynb_to_myst.py:162: myst is available
SKIPPED [1] tests/test_ipynb_to_myst.py:171: myst is available
SKIPPED [17] tests/test_mirror.py:131: pandoc>=2.11 is not available
SKIPPED [11] tests/test_mirror.py:151: sphinx_gallery is not available
SKIPPED [1] tests/test_mirror.py:202: sphinx_gallery is not available
SKIPPED [1] tests/test_mirror.py:208: sphinx_gallery is not available
SKIPPED [1] tests/test_pre_commit_0_ipynb_to_py.py:16: Jupytext folder is not a git repository #814
SKIPPED [1] tests/test_pre_commit_1_sync.py:17: Jupytext folder is not a git repository #814
SKIPPED [1] tests/test_pre_commit_2_sync_nbstripout.py:14: Jupytext folder is not a git repository #814
SKIPPED [1] tests/test_pre_commit_3_sync_black_nbstripout.py:13: Jupytext folder is not a git repository #814
SKIPPED [1] tests/test_pre_commit_4_sync_execute.py:15: Jupytext folder is not a git repository #814
SKIPPED [1] tests/test_pre_commit_5_reformat_markdown.py:15: Jupytext folder is not a git repository #814
SKIPPED [1] tests/test_pre_commit_scripts.py:335: pandoc>=2.11 is not available
SKIPPED [1] tests/test_read_simple_pandoc.py:13: pandoc>=2.11 is not available
SKIPPED [1] tests/test_read_simple_pandoc.py:35: pandoc>=2.11 is not available
SKIPPED [1] tests/test_read_simple_pandoc.py:50: pandoc>=2.11 is not available
SKIPPED [1] tests/test_read_simple_pandoc.py:64: pandoc>=2.11 is not available
SKIPPED [1] tests/test_read_simple_pandoc.py:82: Pandoc is installed
XFAIL tests/test_auto_ext.py::test_auto_from_kernelspecs_works[/home/tkloczko/rpmbuild/BUILD/jupytext-1.11.3/tests/notebooks/ipynb_sage/sage_print_hello.ipynb]
  reason: Sage notebooks have Python in their language_info metadata, see #727
=================================================== 2487 passed, 94 skipped, 1 xfailed, 57 warnings in 171.98s (0:02:51) ===================================================
```


Discussion / hints:

Fix patch:
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))
diff --git a/pyproject.toml b/pyproject.toml
index 87eef4f66..907ad6dcf 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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"
+]


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index c03cdd4a5..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)))
@@ -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')"
 
@@ -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([])
@@ -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"
@@ -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
diff --git a/tests/test_cm_config.py b/tests/test_cm_config.py
index c81d752c4..7bbb48e0c 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|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)
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"))