Skip to content

Commit c87b758

Browse files
authored
Fix tests for Python 3.12.7 (#12993)
1 parent c4997fb commit c87b758

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

tests/test_command_line.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os.path
4+
import sys
45
from typing import Any
56

67
import pytest
@@ -9,6 +10,11 @@
910
from sphinx.cmd.build import get_parser
1011
from sphinx.cmd.make_mode import run_make_mode
1112

13+
broken_argparse = (
14+
sys.version_info[:3] <= (3, 12, 6)
15+
or sys.version_info[:3] == (3, 13, 0)
16+
) # fmt: skip
17+
1218
DEFAULTS = {
1319
'filenames': [],
1420
'jobs': 1,
@@ -79,7 +85,6 @@
7985
'--isolated',
8086
]
8187
OPTS = EARLY_OPTS + LATE_OPTS
82-
OPTS_BUILD_MAIN = BUILDER_BUILD_MAIN + OPTS
8388

8489

8590
def parse_arguments(args: list[str]) -> dict[str, Any]:
@@ -116,7 +121,10 @@ def test_build_main_parse_arguments_pos_middle() -> None:
116121
assert parse_arguments(args) == EXPECTED_BUILD_MAIN
117122

118123

119-
@pytest.mark.xfail(reason='sphinx-build does not yet support filenames after options')
124+
@pytest.mark.xfail(
125+
broken_argparse,
126+
reason='sphinx-build does not yet support filenames after options',
127+
)
120128
def test_build_main_parse_arguments_filenames_last() -> None:
121129
args = [
122130
*POSITIONAL_DIRS,
@@ -136,10 +144,13 @@ def test_build_main_parse_arguments_pos_intermixed(
136144
*LATE_OPTS,
137145
*POSITIONAL_FILENAMES,
138146
]
139-
with pytest.raises(SystemExit):
140-
parse_arguments(args)
141-
stderr = capsys.readouterr().err.splitlines()
142-
assert stderr[-1].endswith('error: unrecognized arguments: filename1 filename2')
147+
if broken_argparse:
148+
with pytest.raises(SystemExit):
149+
parse_arguments(args)
150+
stderr = capsys.readouterr().err.splitlines()
151+
assert stderr[-1].endswith('error: unrecognized arguments: filename1 filename2')
152+
else:
153+
assert parse_arguments(args) == EXPECTED_BUILD_MAIN
143154

144155

145156
def test_make_mode_parse_arguments_pos_first(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -185,10 +196,14 @@ def test_make_mode_parse_arguments_pos_middle(
185196
assert stderr[-1].endswith('error: argument --builder/-b: expected one argument')
186197

187198

188-
@pytest.mark.xfail(reason='sphinx-build does not yet support filenames after options')
199+
@pytest.mark.xfail(
200+
broken_argparse,
201+
reason='sphinx-build does not yet support filenames after options',
202+
)
189203
def test_make_mode_parse_arguments_filenames_last(
190204
monkeypatch: pytest.MonkeyPatch,
191205
) -> None:
206+
# -M <positional...> <opts> <filenames...>
192207
monkeypatch.setattr(make_mode, 'build_main', parse_arguments)
193208
args = [
194209
*BUILDER_MAKE_MODE,
@@ -203,6 +218,7 @@ def test_make_mode_parse_arguments_pos_intermixed(
203218
monkeypatch: pytest.MonkeyPatch,
204219
capsys: pytest.CaptureFixture[str],
205220
) -> None:
221+
# -M <opts> <positional...> <opts> <filenames...>
206222
monkeypatch.setattr(make_mode, 'build_main', parse_arguments)
207223
args = [
208224
*EARLY_OPTS,

0 commit comments

Comments
 (0)