Skip to content

Commit

Permalink
Always define the builder and testroot when using the app fix…
Browse files Browse the repository at this point in the history
…tureture (#12775)
  • Loading branch information
AA-Turner authored Aug 12, 2024
1 parent f7d6f4a commit 0b17bb1
Show file tree
Hide file tree
Showing 61 changed files with 406 additions and 165 deletions.
2 changes: 1 addition & 1 deletion sphinx/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SphinxTestApp(sphinx.application.Sphinx):
It is recommended to use::
@pytest.mark.sphinx('html')
@pytest.mark.sphinx('html', testroot='root')
def test(app):
app = ...
Expand Down
8 changes: 6 additions & 2 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_instantiation(
assert isinstance(app_, sphinx.application.Sphinx)


@pytest.mark.sphinx('html', testroot='root')
def test_events(app):
def empty():
pass
Expand All @@ -75,24 +76,27 @@ def mock_callback(a_app, *args):
assert app.emit('my_event', *emit_args) == [], 'Callback called when disconnected'


@pytest.mark.sphinx('html', testroot='root')
def test_emit_with_nonascii_name_node(app):
node = nodes.section(names=['\u65e5\u672c\u8a9e'])
app.emit('my_event', node)


@pytest.mark.sphinx('html', testroot='root')
def test_extensions(app):
app.setup_extension('shutil')
warning = strip_colors(app.warning.getvalue())
assert "extension 'shutil' has no setup() function" in warning


@pytest.mark.sphinx('html', testroot='root')
def test_extension_in_blacklist(app):
app.setup_extension('sphinxjp.themecore')
msg = strip_colors(app.warning.getvalue())
assert msg.startswith("WARNING: the extension 'sphinxjp.themecore' was")


@pytest.mark.sphinx(testroot='add_source_parser')
@pytest.mark.sphinx('html', testroot='add_source_parser')
def test_add_source_parser(app):
assert set(app.config.source_suffix) == {'.rst', '.test'}

Expand All @@ -106,7 +110,7 @@ def test_add_source_parser(app):
assert app.registry.get_source_parsers()['test'].__name__ == 'TestSourceParser'


@pytest.mark.sphinx(testroot='extensions')
@pytest.mark.sphinx('html', testroot='extensions')
def test_add_is_parallel_allowed(app):
logging.setup(app, app.status, app.warning)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_builders/test_build_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def test_duplicated_toctree_entry(app):
'DO_EPUBCHECK' not in os.environ,
reason='Skipped because DO_EPUBCHECK is not set',
)
@pytest.mark.sphinx('epub')
@pytest.mark.sphinx('epub', testroot='root')
def test_run_epubcheck(app):
app.build()

Expand Down
4 changes: 4 additions & 0 deletions tests/test_builders/test_build_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_Catalog_duplicated_message():

@pytest.mark.sphinx(
'gettext',
testroot='root',
srcdir='root-gettext',
)
def test_build_gettext(app):
Expand All @@ -66,6 +67,7 @@ def test_build_gettext(app):

@pytest.mark.sphinx(
'gettext',
testroot='root',
srcdir='root-gettext',
)
def test_msgfmt(app):
Expand Down Expand Up @@ -212,6 +214,7 @@ def test_gettext_custom_output_template(app):

@pytest.mark.sphinx(
'gettext',
testroot='root',
srcdir='root-gettext',
confoverrides={'gettext_compact': 'documentation'},
)
Expand Down Expand Up @@ -283,6 +286,7 @@ def test_gettext_prolog_epilog_substitution_excluded(app):

@pytest.mark.sphinx(
'gettext',
testroot='root',
srcdir='gettext',
confoverrides={
'gettext_compact': False,
Expand Down
5 changes: 4 additions & 1 deletion tests/test_builders/test_build_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_html4_error(make_app, tmp_path):
),
],
)
@pytest.mark.sphinx('html')
@pytest.mark.sphinx('html', testroot='root')
@pytest.mark.test_params(shared_result='test_build_html_output_docutils18')
def test_docutils_output(app, cached_etree_parse, fname, path, check):
app.build()
Expand All @@ -133,6 +133,7 @@ def test_docutils_output(app, cached_etree_parse, fname, path, check):

@pytest.mark.sphinx(
'html',
testroot='root',
parallel=2,
)
def test_html_parallel(app):
Expand Down Expand Up @@ -489,6 +490,7 @@ def test_html_baseurl_and_html_file_suffix(app):


@pytest.mark.sphinx(
'html',
testroot='basic',
srcdir='validate_html_extra_path',
)
Expand All @@ -508,6 +510,7 @@ def test_validate_html_extra_path(app):


@pytest.mark.sphinx(
'html',
testroot='basic',
srcdir='validate_html_static_path',
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_builders/test_build_html_5_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ def checker(nodes: Iterable[Element]) -> Literal[True]:
)
@pytest.mark.sphinx(
'html',
testroot='root',
tags=['testtag'],
confoverrides={'html_context.hckey_co': 'hcval_co'},
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_builders/test_build_html_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest


@pytest.mark.sphinx('html')
@pytest.mark.sphinx('html', testroot='root')
def test_html_download(app):
app.build()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_builders/test_build_html_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_html_local_logo(app):
assert (app.outdir / '_static/img.png').exists()


@pytest.mark.sphinx(testroot='html_scaled_image_link')
@pytest.mark.sphinx('html', testroot='html_scaled_image_link')
def test_html_scaled_image_link(app):
app.build()
context = (app.outdir / 'index.html').read_text(encoding='utf8')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_builders/test_build_html_toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tests.test_builders.xpath_util import check_xpath


@pytest.mark.sphinx(testroot='toctree-glob')
@pytest.mark.sphinx('html', testroot='toctree-glob')
def test_relations(app):
app.build(force_all=True)
assert app.builder.relations['index'] == [None, None, 'foo']
Expand Down Expand Up @@ -39,6 +39,7 @@ def test_singlehtml_toctree(app):


@pytest.mark.sphinx(
'html',
testroot='toctree',
srcdir='numbered-toctree',
)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_builders/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def do_GET(self):
)
@pytest.mark.sphinx(
'latex',
testroot='root',
freshenv=True,
)
def test_build_latex_doc(app, engine, docclass, python_maximum_signature_line_length):
Expand Down Expand Up @@ -163,7 +164,7 @@ def test_build_latex_doc(app, engine, docclass, python_maximum_signature_line_le
compile_latex_document(app, 'sphinxtests.tex', docclass)


@pytest.mark.sphinx('latex')
@pytest.mark.sphinx('latex', testroot='root')
def test_writer(app):
app.build(force_all=True)
result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8')
Expand Down Expand Up @@ -928,7 +929,7 @@ def test_polyglossia_with_language_de_1901(app):
assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.\@{} }}' in result


@pytest.mark.sphinx('latex')
@pytest.mark.sphinx('latex', testroot='root')
def test_footnote(app):
app.build(force_all=True)
result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8')
Expand Down
15 changes: 12 additions & 3 deletions tests/test_builders/test_build_linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ class FakeResponse:
url = 'http://localhost/'


@pytest.mark.sphinx('html', testroot='root')
def test_limit_rate_default_sleep(app: SphinxTestApp) -> None:
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), {})
with mock.patch('time.time', return_value=0.0):
Expand All @@ -1154,7 +1155,9 @@ def test_limit_rate_default_sleep(app: SphinxTestApp) -> None:
assert next_check == 60.0


@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 0.0})
@pytest.mark.sphinx(
'html', testroot='root', confoverrides={'linkcheck_rate_limit_timeout': 0.0}
)
def test_limit_rate_user_max_delay(app: SphinxTestApp) -> None:
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), {})
next_check = worker.limit_rate(
Expand All @@ -1163,6 +1166,7 @@ def test_limit_rate_user_max_delay(app: SphinxTestApp) -> None:
assert next_check is None


@pytest.mark.sphinx('html', testroot='root')
def test_limit_rate_doubles_previous_wait_time(app: SphinxTestApp) -> None:
rate_limits = {'localhost': RateLimit(60.0, 0.0)}
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), rate_limits)
Expand All @@ -1173,7 +1177,9 @@ def test_limit_rate_doubles_previous_wait_time(app: SphinxTestApp) -> None:
assert next_check == 120.0


@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90})
@pytest.mark.sphinx(
'html', testroot='root', confoverrides={'linkcheck_rate_limit_timeout': 90}
)
def test_limit_rate_clips_wait_time_to_max_time(app: SphinxTestApp) -> None:
rate_limits = {'localhost': RateLimit(60.0, 0.0)}
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), rate_limits)
Expand All @@ -1185,7 +1191,9 @@ def test_limit_rate_clips_wait_time_to_max_time(app: SphinxTestApp) -> None:
assert app.warning.getvalue() == ''


@pytest.mark.sphinx(confoverrides={'linkcheck_rate_limit_timeout': 90.0})
@pytest.mark.sphinx(
'html', testroot='root', confoverrides={'linkcheck_rate_limit_timeout': 90.0}
)
def test_limit_rate_bails_out_after_waiting_max_time(app: SphinxTestApp) -> None:
rate_limits = {'localhost': RateLimit(90.0, 0.0)}
worker = HyperlinkAvailabilityCheckWorker(app.config, Queue(), Queue(), rate_limits)
Expand All @@ -1197,6 +1205,7 @@ def test_limit_rate_bails_out_after_waiting_max_time(app: SphinxTestApp) -> None


@mock.patch('sphinx.util.requests.requests.Session.get_adapter')
@pytest.mark.sphinx('html', testroot='root')
def test_connection_contention(get_adapter, app, capsys):
# Create a shared, but limited-size, connection pool
import requests
Expand Down
2 changes: 1 addition & 1 deletion tests/test_builders/test_build_manpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sphinx.config import Config


@pytest.mark.sphinx('man')
@pytest.mark.sphinx('man', testroot='root')
def test_all(app):
app.build(force_all=True)
assert (app.outdir / 'sphinxtests.1').exists()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_builders/test_build_texinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sphinx.writers.texinfo import TexinfoTranslator


@pytest.mark.sphinx('texinfo')
@pytest.mark.sphinx('texinfo', testroot='root')
def test_texinfo(app):
TexinfoTranslator.ignore_missing_images = True
app.build(force_all=True)
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_default_texinfo_documents():
assert default_texinfo_documents(config) == expected


@pytest.mark.sphinx('texinfo')
@pytest.mark.sphinx('texinfo', testroot='root')
def test_texinfo_escape_id(app):
settings = Mock(title='', texinfo_dir_entry='', texinfo_elements={})
document = new_document('', settings)
Expand All @@ -104,7 +104,7 @@ def test_texinfo_footnote(app):
assert 'First footnote: @footnote{\nFirst\n}' in output


@pytest.mark.sphinx('texinfo')
@pytest.mark.sphinx('texinfo', testroot='root')
def test_texinfo_xrefs(app):
app.build(force_all=True)
output = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
Expand Down
7 changes: 1 addition & 6 deletions tests/test_builders/test_build_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@


def with_text_app(*args: Any, **kw: Any) -> pytest.MarkDecorator:
default_kw = {
'buildername': 'text',
'testroot': 'build-text',
}
default_kw.update(kw)
return pytest.mark.sphinx(*args, **default_kw)
return pytest.mark.sphinx(*args, buildername='text', testroot='build-text', **kw)


@with_text_app()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@pytest.mark.sphinx(
'dummy',
testroot='root',
srcdir='test_builder',
freshenv=True,
)
Expand Down
11 changes: 9 additions & 2 deletions tests/test_config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def test_config_opt_deprecated(recwarn):


@pytest.mark.sphinx(
'html',
testroot='config',
confoverrides={
'root_doc': 'root',
Expand Down Expand Up @@ -458,6 +459,8 @@ def test_config_eol(logger, tmp_path):


@pytest.mark.sphinx(
'html',
testroot='root',
confoverrides={'root_doc': 123, 'language': 'foo', 'primary_domain': None},
)
def test_builtin_conf(app):
Expand Down Expand Up @@ -603,7 +606,7 @@ def test_check_any(logger):
]


@pytest.mark.sphinx(testroot='nitpicky-warnings')
@pytest.mark.sphinx('html', testroot='nitpicky-warnings')
def test_nitpick_base(app):
app.build(force_all=True)

Expand All @@ -613,6 +616,7 @@ def test_nitpick_base(app):


@pytest.mark.sphinx(
'html',
testroot='nitpicky-warnings',
confoverrides={
'nitpick_ignore': {
Expand All @@ -629,6 +633,7 @@ def test_nitpick_ignore(app):


@pytest.mark.sphinx(
'html',
testroot='nitpicky-warnings',
confoverrides={
'nitpick_ignore_regex': [
Expand All @@ -643,6 +648,7 @@ def test_nitpick_ignore_regex1(app):


@pytest.mark.sphinx(
'html',
testroot='nitpicky-warnings',
confoverrides={
'nitpick_ignore_regex': [
Expand All @@ -657,6 +663,7 @@ def test_nitpick_ignore_regex2(app):


@pytest.mark.sphinx(
'html',
testroot='nitpicky-warnings',
confoverrides={
'nitpick_ignore_regex': [
Expand Down Expand Up @@ -754,7 +761,7 @@ def source_date_year(request, monkeypatch):
yield None


@pytest.mark.sphinx(testroot='copyright-multiline')
@pytest.mark.sphinx('html', testroot='copyright-multiline')
def test_multi_line_copyright(source_date_year, app, monkeypatch):
app.build(force_all=True)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_directives/test_directive_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_LiteralIncludeReader_lines_and_lineno_match1(literal_inc_path):
assert reader.lineno_start == 3


@pytest.mark.sphinx # init locale for errors
@pytest.mark.sphinx('html', testroot='root') # init locale for errors
def test_LiteralIncludeReader_lines_and_lineno_match2(literal_inc_path, app):
options = {'lines': '0,3,5', 'lineno-match': True}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand All @@ -111,7 +111,7 @@ def test_LiteralIncludeReader_lines_and_lineno_match2(literal_inc_path, app):
reader.read()


@pytest.mark.sphinx # init locale for errors
@pytest.mark.sphinx('html', testroot='root') # init locale for errors
def test_LiteralIncludeReader_lines_and_lineno_match3(literal_inc_path, app):
options = {'lines': '100-', 'lineno-match': True}
reader = LiteralIncludeReader(literal_inc_path, options, DUMMY_CONFIG)
Expand Down
Loading

0 comments on commit 0b17bb1

Please sign in to comment.