Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
allow pytest to process deprecations in docstrings
Browse files Browse the repository at this point in the history
We monkey-patch warnings just as we do in the original doctesting
framework.
Needs more testing.
  • Loading branch information
dimpase committed Dec 7, 2022
1 parent d474c3a commit 92bbf1d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
# - inject it into globals namespace for doctests
import sage.all
from sage.doctest.parsing import SageDocTestParser, SageOutputChecker
from sage.doctest.forker import showwarning_with_traceback
import warnings

warnings.showwarning = showwarning_with_traceback

class SageDoctestModule(DoctestModule):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def showwarning_with_traceback(message, category, filename, lineno, file=None, l
lines.extend(traceback.format_exception_only(category, category(message)))

if file is None:
file = sys.stderr
file = sys.stdout
try:
file.writelines(lines)
file.flush()
Expand Down
2 changes: 1 addition & 1 deletion src/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ exclude =
[pytest]
python_files = *_test.py
norecursedirs = local prefix venv build pkgs .git src/doc src/bin
addopts = --import-mode importlib
addopts = --import-mode importlib -p no:warnings
doctest_optionflags = NORMALIZE_WHITESPACE ELLIPSIS
[coverage:run]
Expand Down

0 comments on commit 92bbf1d

Please sign in to comment.