Skip to content

Commit 9b4e192

Browse files
authored
Update testing env to include PendingDeprecation warnings (#3114)
Closes #2716 According to the official python docs, `PendingDeprecation` warnings are [ignored by default](https://docs.python.org/3/library/exceptions.html#PendingDeprecationWarning) unless [Python Development Mode](https://docs.python.org/3/library/devmode.html) is enabled (done either through the `-Xdev` or `-Wd` flags when invoking `python` or by setting the environment variable `PYTHONDEVMODE=1`). This PR sets the `tox` environment to run using dev mode with the `PYTHONDEVMODE` env var.
1 parent 42ec9e4 commit 9b4e192

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

docs/guides/circuit-library.ipynb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@
5656
"cell_type": "code",
5757
"execution_count": 1,
5858
"id": "a846a845-7ac5-4c92-b124-d2b90a773ba2",
59-
"metadata": {},
59+
"metadata": {
60+
"tags": [
61+
"ignore-warnings"
62+
]
63+
},
6064
"outputs": [
6165
{
6266
"data": {

docs/guides/qiskit-addons-mpf-get-started.ipynb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@
157157
"cell_type": "code",
158158
"execution_count": 3,
159159
"id": "d2f308be-2c13-475c-b9a7-390883a620bc",
160-
"metadata": {},
160+
"metadata": {
161+
"tags": [
162+
"ignore-warnings"
163+
]
164+
},
161165
"outputs": [
162166
{
163167
"name": "stdout",

scripts/nb-tester/qiskit_docs_notebook_tester/config.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# Import with underscores to avoid interfering with user-facing code.
2929
from matplotlib import set_loglevel as _set_mpl_loglevel
3030
31+
3132
# See https://github.com/matplotlib/matplotlib/issues/23326#issuecomment-1164772708
3233
_set_mpl_loglevel("critical")
3334
"""
@@ -73,6 +74,12 @@ def get_notebook_jobs(args: argparse.Namespace) -> Iterator[NotebookJob]:
7374
)
7475
continue
7576

77+
warning_filter = ""
78+
if config.check_pending_deprecations:
79+
warning_filter = "import warnings as _warnings \
80+
\n_warnings.simplefilter('default', category=PendingDeprecationWarning)"
81+
pre_execute_code = PRE_EXECUTE_CODE + warning_filter
82+
7683
patch = config.get_patch_for_group(group)
7784

7885
if patch and not "# nb-tester: allow-write" in patch:
@@ -84,7 +91,7 @@ def get_notebook_jobs(args: argparse.Namespace) -> Iterator[NotebookJob]:
8491

8592
yield NotebookJob(
8693
path=Path(path),
87-
pre_execute_code=PRE_EXECUTE_CODE,
94+
pre_execute_code=pre_execute_code,
8895
backend_patch=patch,
8996
cell_timeout=config.cell_timeout,
9097
write=write,
@@ -96,6 +103,7 @@ class Config:
96103
cli_filenames: list[Path]
97104
cell_timeout: int
98105
test_strategy: str
106+
check_pending_deprecations: bool
99107
write: bool
100108
groups: list[dict]
101109

@@ -133,6 +141,7 @@ def from_args(cls, args: argparse.Namespace) -> Config:
133141
cli_filenames=cli_filenames,
134142
cell_timeout=args.cell_timeout,
135143
test_strategy="custom",
144+
check_pending_deprecations=args.check_pending_deprecations,
136145
write=args.write,
137146
groups=groups,
138147
)
@@ -150,16 +159,14 @@ def from_args(cls, args: argparse.Namespace) -> Config:
150159
{"name": key, **value} for key, value in config_file["groups"].items()
151160
]
152161
test_strategy = args.test_strategy or config_file["default-strategy"]
153-
cell_timeout = (
154-
args.cell_timeout or
155-
config_file.get("test-strategies", {})
156-
.get(test_strategy, {})
157-
.get("timeout", None)
158-
)
162+
cell_timeout = args.cell_timeout or config_file.get("test-strategies", {}).get(
163+
test_strategy, {}
164+
).get("timeout", None)
159165
return cls(
160166
cli_filenames=args.filenames,
161167
cell_timeout=cell_timeout,
162168
test_strategy=test_strategy,
169+
check_pending_deprecations=args.check_pending_deprecations,
163170
write=args.write,
164171
groups=groups,
165172
)
@@ -261,4 +268,9 @@ def get_parser() -> argparse.ArgumentParser:
261268
"useful to set if your patch does not use QiskitRuntimeService"
262269
),
263270
)
271+
parser.add_argument(
272+
"--check-pending-deprecations",
273+
action="store_true",
274+
help="Include checking for PendingDeprecationWarnings in notebook outputs",
275+
)
264276
return parser

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ deps =
88
-e scripts/nb-tester
99
-r scripts/nb-tester/requirements.txt
1010
setenv = PYDEVD_DISABLE_FILE_VALIDATION=1
11-
commands = test-docs-notebooks {posargs} --config-path scripts/config/notebook-testing.toml
11+
commands = test-docs-notebooks {posargs} --check-pending-deprecations --config-path scripts/config/notebook-testing.toml
1212

1313
[testenv:{lint,fix}]
1414
deps =

0 commit comments

Comments
 (0)