|
1 | 1 |
|
2 | 2 | import os |
3 | 3 | import pytest |
4 | | -from nbconvert.preprocessors.execute import CellExecutionError |
| 4 | +import warnings |
| 5 | + |
| 6 | +# importing nbconvert components such as nbconvert.preprocessors.execute |
| 7 | +# while in pytest causes the following warning: |
| 8 | +# |
| 9 | +# jupyter_client/connect.py:27: DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs |
| 10 | +# given by the platformdirs library. To remove this warning and |
| 11 | +# see the appropriate new directories, set the environment variable |
| 12 | +# `JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`. |
| 13 | +# The use of platformdirs will be the default in `jupyter_core` v6 |
| 14 | +# from jupyter_core.paths import jupyter_data_dir |
| 15 | +# -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html |
| 16 | +# |
| 17 | +# likely this is from some environment isolation set up by pytest |
| 18 | +# the same code does not warn when executing directly |
| 19 | +# |
| 20 | +# so we are going to trigger the warning on first import, so it is caught |
| 21 | +# and does not reoccur when we import wvpy.jtools components |
| 22 | +with warnings.catch_warnings(): |
| 23 | + warnings.simplefilter("ignore") |
| 24 | + from nbconvert.preprocessors.execute import CellExecutionError # even importing this causes warning |
5 | 25 |
|
6 | 26 | from wvpy.jtools import render_as_html, convert_py_code_to_notebook, convert_notebook_code_to_py |
7 | 27 |
|
8 | 28 |
|
9 | | -# Was seeing: |
10 | | -# nbconvert/filters/ansi.py:60: DeprecationWarning: 'jinja2.escape' is deprecated and will be removed in Jinja 3.1. Import 'markupsafe.escape' instead. |
11 | | -# @pytest.mark.filterwarnings("ignore:") |
| 29 | +# confirm we have not killed all warnings |
| 30 | +def test_still_warns_even_after_monkeying(): |
| 31 | + with pytest.warns(DeprecationWarning): |
| 32 | + warnings.warn(DeprecationWarning("test warning")) |
| 33 | + |
| 34 | + |
12 | 35 | def test_jupyter_notebook_good(): |
13 | 36 | source_dir = os.path.dirname(os.path.realpath(__file__)) |
14 | 37 | orig_wd = os.getcwd() |
@@ -54,7 +77,7 @@ def test_jupyter_notebook_bad(): |
54 | 77 | + 4) |
55 | 78 | """ |
56 | 79 |
|
57 | | -# @pytest.mark.filterwarnings("ignore:") |
| 80 | + |
58 | 81 | def test_jupyter_notebook_parameterized_good(): |
59 | 82 | source_dir = os.path.dirname(os.path.realpath(__file__)) |
60 | 83 | orig_wd = os.getcwd() |
|
0 commit comments