Skip to content

Commit

Permalink
[tests] correctly intercept or suppress warnings in tests (#12085)
Browse files Browse the repository at this point in the history
  • Loading branch information
picnixz authored Mar 14, 2024
1 parent d6f49f9 commit dbb4da3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ empty_parameter_set_mark = "xfail"
filterwarnings = [
"all",
"ignore::DeprecationWarning:docutils.io",
"ignore:Distutils was imported before Setuptools:UserWarning:_distutils_hack",
"ignore:Setuptools is replacing distutils:UserWarning:_distutils_hack",
"ignore::DeprecationWarning:pyximport.pyximport",
"ignore::ImportWarning:importlib._bootstrap",
]
Expand Down
7 changes: 5 additions & 2 deletions tests/test_builders/test_build_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from sphinx.builders.html import validate_html_extra_path, validate_html_static_path
from sphinx.deprecation import RemovedInSphinx80Warning
from sphinx.errors import ConfigError
from sphinx.util.inventory import InventoryFile

Expand Down Expand Up @@ -341,7 +342,8 @@ def test_validate_html_extra_path(app):
app.outdir, # outdir
app.outdir / '_static', # inside outdir
]
validate_html_extra_path(app, app.config)
with pytest.warns(RemovedInSphinx80Warning, match='Use "pathlib.Path" or "os.fspath" instead'):
validate_html_extra_path(app, app.config)
assert app.config.html_extra_path == ['_static']


Expand All @@ -354,7 +356,8 @@ def test_validate_html_static_path(app):
app.outdir, # outdir
app.outdir / '_static', # inside outdir
]
validate_html_static_path(app, app.config)
with pytest.warns(RemovedInSphinx80Warning, match='Use "pathlib.Path" or "os.fspath" instead'):
validate_html_static_path(app, app.config)
assert app.config.html_static_path == ['_static']


Expand Down
6 changes: 5 additions & 1 deletion tests/test_builders/test_build_linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
HyperlinkAvailabilityCheckWorker,
RateLimit,
)
from sphinx.deprecation import RemovedInSphinx80Warning
from sphinx.testing.util import strip_escseq
from sphinx.util import requests

Expand Down Expand Up @@ -413,7 +414,10 @@ def test_unauthorized_broken(app):
'linkcheck', testroot='linkcheck-localserver', freshenv=True,
confoverrides={'linkcheck_auth': [(r'^$', ('user1', 'password'))]})
def test_auth_header_no_match(app):
with http_server(custom_handler(valid_credentials=("user1", "password"))):
with (
http_server(custom_handler(valid_credentials=("user1", "password"))),
pytest.warns(RemovedInSphinx80Warning, match='linkcheck builder encountered an HTTP 401'),
):
app.build()

with open(app.outdir / "output.json", encoding="utf-8") as fp:
Expand Down

0 comments on commit dbb4da3

Please sign in to comment.