diff --git a/tests/test_builders/test_build_html.py b/tests/test_builders/test_build_html.py
index 65ab6a54e..ad753c891 100644
--- a/tests/test_builders/test_build_html.py
+++ b/tests/test_builders/test_build_html.py
@@ -1,40 +1,17 @@
"""Test the HTML builder and check output against XPath."""
-import os
import posixpath
import re
-import sys
import pytest
from sphinx.builders.html import validate_html_extra_path, validate_html_static_path
from sphinx.errors import ConfigError
-from sphinx.testing.util import strip_escseq
from sphinx.util.inventory import InventoryFile
FIGURE_CAPTION = ".//figure/figcaption/p"
-ENV_WARNINGS = """\
-{root}/autodoc_fodder.py:docstring of autodoc_fodder.MarkupError:\\d+: \
-WARNING: Explicit markup ends without a blank line; unexpected unindent.
-{root}/index.rst:\\d+: WARNING: Encoding 'utf-8-sig' used for reading included \
-file '{root}/wrongenc.inc' seems to be wrong, try giving an :encoding: option
-{root}/index.rst:\\d+: WARNING: invalid single index entry ''
-{root}/index.rst:\\d+: WARNING: image file not readable: foo.png
-{root}/index.rst:\\d+: WARNING: download file not readable: {root}/nonexisting.png
-{root}/undecodable.rst:\\d+: WARNING: undecodable source characters, replacing \
-with "\\?": b?'here: >>>(\\\\|/)xbb<<<((\\\\|/)r)?'
-"""
-
-HTML_WARNINGS = ENV_WARNINGS + """\
-{root}/index.rst:\\d+: WARNING: unknown option: '&option'
-{root}/index.rst:\\d+: WARNING: citation not found: missing
-{root}/index.rst:\\d+: WARNING: a suitable image for html builder not found: foo.\\*
-{root}/index.rst:\\d+: WARNING: Lexing literal_block ".*" as "c" resulted in an error at token: ".*". Retrying in relaxed mode.
-"""
-
-
def check_xpath(etree, fname, path, check, be_found=True):
nodes = list(etree.findall(path))
if check is None:
@@ -71,19 +48,6 @@ def check_xpath(etree, fname, path, check, be_found=True):
raise AssertionError(msg)
-@pytest.mark.sphinx('html', testroot='warnings', freshenv=True)
-def test_html_warnings(app, warning):
- app.build(force_all=True)
- warnings = strip_escseq(re.sub(re.escape(os.sep) + '{1,2}', '/', warning.getvalue()))
- warnings_exp = HTML_WARNINGS.format(root=re.escape(app.srcdir.as_posix()))
- assert re.match(warnings_exp + '$', warnings), (
- "Warnings don't match:\n"
- + f'--- Expected (regex):\n{warnings_exp}\n'
- + f'--- Got:\n{warnings}'
- )
- sys.modules.pop('autodoc_fodder', None)
-
-
def test_html4_error(make_app, tmp_path):
(tmp_path / 'conf.py').write_text('', encoding='utf-8')
with pytest.raises(
diff --git a/tests/test_builders/test_build_latex.py b/tests/test_builders/test_build_latex.py
index 75e649f4d..15de39816 100644
--- a/tests/test_builders/test_build_latex.py
+++ b/tests/test_builders/test_build_latex.py
@@ -3,7 +3,6 @@
import os
import re
import subprocess
-import sys
from itertools import chain, product
from pathlib import Path
from shutil import copyfile
@@ -16,12 +15,9 @@ from sphinx.config import Config
from sphinx.errors import SphinxError
from sphinx.ext.intersphinx import load_mappings, normalize_intersphinx_mapping
from sphinx.ext.intersphinx import setup as intersphinx_setup
-from sphinx.testing.util import strip_escseq
from sphinx.util.osutil import ensuredir
from sphinx.writers.latex import LaTeXTranslator
-from tests.test_builders.test_build_html import ENV_WARNINGS
-
try:
from contextlib import chdir
except ImportError:
@@ -34,14 +30,6 @@ STYLEFILES = ['article.cls', 'fancyhdr.sty', 'titlesec.sty', 'amsmath.sty',
'fncychap.sty', 'geometry.sty', 'kvoptions.sty', 'hyperref.sty',
'booktabs.sty']
-LATEX_WARNINGS = ENV_WARNINGS + """\
-{root}/index.rst:\\d+: WARNING: unknown option: '&option'
-{root}/index.rst:\\d+: WARNING: citation not found: missing
-{root}/index.rst:\\d+: WARNING: a suitable image for latex builder not found: foo.\\*
-{root}/index.rst:\\d+: WARNING: Lexing literal_block ".*" as "c" resulted in an error at token: ".*". Retrying in relaxed mode.
-"""
-
-
# only run latex if all needed packages are there
def kpsetest(*filenames):
try:
@@ -174,19 +162,6 @@ def test_writer(app, status, warning):
'\n\n\\end{sphinxseealso}\n\n' in result)
-@pytest.mark.sphinx('latex', testroot='warnings', freshenv=True)
-def test_latex_warnings(app, status, warning):
- app.build(force_all=True)
- warnings = strip_escseq(re.sub(re.escape(os.sep) + '{1,2}', '/', warning.getvalue()))
- warnings_exp = LATEX_WARNINGS.format(root=re.escape(app.srcdir.as_posix()))
- assert re.match(warnings_exp + '$', warnings), (
- "Warnings don't match:\n"
- + f'--- Expected (regex):\n{warnings_exp}\n'
- + f'--- Got:\n{warnings}'
- )
- sys.modules.pop('autodoc_fodder', None)
-
-
@pytest.mark.sphinx('latex', testroot='basic')
def test_latex_basic(app, status, warning):
app.build(force_all=True)
diff --git a/tests/test_builders/test_build_texinfo.py b/tests/test_builders/test_build_texinfo.py
index 7edf82dab..f9effb2c0 100644
--- a/tests/test_builders/test_build_texinfo.py
+++ b/tests/test_builders/test_build_texinfo.py
@@ -1,9 +1,7 @@
"""Test the build process with Texinfo builder with the test root."""
-import os
import re
import subprocess
-import sys
from pathlib import Path
from subprocess import CalledProcessError
from unittest.mock import Mock
@@ -12,33 +10,9 @@ import pytest
from sphinx.builders.texinfo import default_texinfo_documents
from sphinx.config import Config
-from sphinx.testing.util import strip_escseq
from sphinx.util.docutils import new_document
from sphinx.writers.texinfo import TexinfoTranslator
-from tests.test_builders.test_build_html import ENV_WARNINGS
-
-TEXINFO_WARNINGS = ENV_WARNINGS + """\
-{root}/index.rst:\\d+: WARNING: unknown option: '&option'
-{root}/index.rst:\\d+: WARNING: citation not found: missing
-{root}/index.rst:\\d+: WARNING: a suitable image for texinfo builder not found: foo.\\*
-{root}/index.rst:\\d+: WARNING: a suitable image for texinfo builder not found: \
-\\['application/pdf', 'image/svg\\+xml'\\] \\(svgimg.\\*\\)
-"""
-
-
-@pytest.mark.sphinx('texinfo', testroot='warnings', freshenv=True)
-def test_texinfo_warnings(app, status, warning):
- app.build(force_all=True)
- warnings = strip_escseq(re.sub(re.escape(os.sep) + '{1,2}', '/', warning.getvalue()))
- warnings_exp = TEXINFO_WARNINGS.format(root=re.escape(app.srcdir.as_posix()))
- assert re.match(warnings_exp + '$', warnings), (
- "Warnings don't match:\n"
- + f'--- Expected (regex):\n{warnings_exp}\n'
- + f'--- Got:\n{warnings}'
- )
- sys.modules.pop('autodoc_fodder', None)
-
@pytest.mark.sphinx('texinfo')
def test_texinfo(app, status, warning):
diff --git a/tests/test_builders/test_build_warnings.py b/tests/test_builders/test_build_warnings.py
new file mode 100644
index 000000000..852d7647a
--- /dev/null
+++ b/tests/test_builders/test_build_warnings.py
@@ -0,0 +1,72 @@
+import os
+import re
+import sys
+
+import pytest
+
+from sphinx.testing.util import strip_escseq
+
+ENV_WARNINGS = """\
+{root}/autodoc_fodder.py:docstring of autodoc_fodder.MarkupError:\\d+: \
+WARNING: Explicit markup ends without a blank line; unexpected unindent.
+{root}/index.rst:\\d+: WARNING: Encoding 'utf-8-sig' used for reading included \
+file '{root}/wrongenc.inc' seems to be wrong, try giving an :encoding: option
+{root}/index.rst:\\d+: WARNING: invalid single index entry ''
+{root}/index.rst:\\d+: WARNING: image file not readable: foo.png
+{root}/index.rst:\\d+: WARNING: download file not readable: {root}/nonexisting.png
+{root}/undecodable.rst:\\d+: WARNING: undecodable source characters, replacing \
+with "\\?": b?'here: >>>(\\\\|/)xbb<<<((\\\\|/)r)?'
+"""
+
+HTML_WARNINGS = ENV_WARNINGS + """\
+{root}/index.rst:\\d+: WARNING: unknown option: '&option'
+{root}/index.rst:\\d+: WARNING: citation not found: missing
+{root}/index.rst:\\d+: WARNING: a suitable image for html builder not found: foo.\\*
+{root}/index.rst:\\d+: WARNING: Lexing literal_block ".*" as "c" resulted in an error at token: ".*". Retrying in relaxed mode.
+"""
+
+LATEX_WARNINGS = ENV_WARNINGS + """\
+{root}/index.rst:\\d+: WARNING: unknown option: '&option'
+{root}/index.rst:\\d+: WARNING: citation not found: missing
+{root}/index.rst:\\d+: WARNING: a suitable image for latex builder not found: foo.\\*
+{root}/index.rst:\\d+: WARNING: Lexing literal_block ".*" as "c" resulted in an error at token: ".*". Retrying in relaxed mode.
+"""
+
+TEXINFO_WARNINGS = ENV_WARNINGS + """\
+{root}/index.rst:\\d+: WARNING: unknown option: '&option'
+{root}/index.rst:\\d+: WARNING: citation not found: missing
+{root}/index.rst:\\d+: WARNING: a suitable image for texinfo builder not found: foo.\\*
+{root}/index.rst:\\d+: WARNING: a suitable image for texinfo builder not found: \
+\\['application/pdf', 'image/svg\\+xml'\\] \\(svgimg.\\*\\)
+"""
+
+
+def _check_warnings(expected_warnings: str, warning: str) -> None:
+ warnings = strip_escseq(re.sub(re.escape(os.sep) + '{1,2}', '/', warning))
+ assert re.match(f'{expected_warnings}$', warnings), (
+ "Warnings don't match:\n"
+ + f'--- Expected (regex):\n{expected_warnings}\n'
+ + f'--- Got:\n{warnings}'
+ )
+ sys.modules.pop('autodoc_fodder', None)
+
+
+@pytest.mark.sphinx('html', testroot='warnings', freshenv=True)
+def test_html_warnings(app, warning):
+ app.build(force_all=True)
+ warnings_exp = HTML_WARNINGS.format(root=re.escape(app.srcdir.as_posix()))
+ _check_warnings(warnings_exp, warning.getvalue())
+
+
+@pytest.mark.sphinx('latex', testroot='warnings', freshenv=True)
+def test_latex_warnings(app, warning):
+ app.build(force_all=True)
+ warnings_exp = LATEX_WARNINGS.format(root=re.escape(app.srcdir.as_posix()))
+ _check_warnings(warnings_exp, warning.getvalue())
+
+
+@pytest.mark.sphinx('texinfo', testroot='warnings', freshenv=True)
+def test_texinfo_warnings(app, warning):
+ app.build(force_all=True)
+ warnings_exp = TEXINFO_WARNINGS.format(root=re.escape(app.srcdir.as_posix()))
+ _check_warnings(warnings_exp, warning.getvalue())