Skip to content

Commit 3daa5c1

Browse files
committed
Fix tests that use sphinx-build
1 parent da49af1 commit 3daa5c1

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ homepage = "https://github.com/thisch/pytest-sphinx"
5050
[build-system]
5151
requires = ["setuptools"]
5252
build-backend = "setuptools.build_meta"
53+
54+
[dependency-groups]
55+
dev = [
56+
"sphinx>=8.1.3",
57+
]

tests/test_sphinx_doctest.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import subprocess
6+
import sys
67
import textwrap
78
from pathlib import Path
89
from typing import Iterator
@@ -15,6 +16,13 @@
1516
logger = logging.getLogger(__name__)
1617

1718

19+
def assert_1_item_passed(output):
20+
if sys.version_info >= (3, 13):
21+
assert "1 item passed all tests" in output
22+
else:
23+
assert "1 items passed all tests" in output
24+
25+
1826
class SphinxDoctestRunner:
1927
def __init__(self, tmp_path: Path) -> None:
2028
self.tmp_path: Path = tmp_path
@@ -105,7 +113,7 @@ def test_simple_doctest_success(sphinx_tester: SphinxDoctestRunner) -> None:
105113
6
106114
"""
107115
)
108-
assert "1 items passed all tests" in output
116+
assert_1_item_passed(output)
109117

110118

111119
class TestDirectives:
@@ -123,7 +131,7 @@ def test_testcode(
123131
"""
124132

125133
sphinx_output = sphinx_tester(code)
126-
assert "1 items passed all tests" in sphinx_output
134+
assert_1_item_passed(sphinx_output)
127135

128136
plugin_result = testdir.runpytest("--doctest-glob=index.rst").stdout
129137
plugin_result.fnmatch_lines(["*=== 1 passed in *"])
@@ -139,7 +147,7 @@ def test_doctest(
139147
"""
140148

141149
sphinx_output = sphinx_tester(code)
142-
assert "1 items passed all tests" in sphinx_output
150+
assert_1_item_passed(sphinx_output)
143151

144152
plugin_result = testdir.runpytest("--doctest-glob=index.rst").stdout
145153
plugin_result.fnmatch_lines(["*=== 1 passed in *"])
@@ -170,7 +178,7 @@ def test_doctest_multiple(
170178
"""
171179

172180
sphinx_output = sphinx_tester(code)
173-
assert "1 items passed all tests" in sphinx_output
181+
assert_1_item_passed(sphinx_output)
174182

175183
plugin_result = testdir.runpytest("--doctest-glob=index.rst").stdout
176184
plugin_result.fnmatch_lines(["*=== 1 passed in *"])
@@ -201,7 +209,7 @@ def test_skipif_true(
201209
assert "1 failure in tests" in sphinx_output
202210
plugin_output.fnmatch_lines(["*=== 1 failed in *"])
203211
else:
204-
assert "1 items passed all tests" in sphinx_output
212+
assert_1_item_passed(sphinx_output)
205213
plugin_output.fnmatch_lines(["*=== 1 passed in *"])
206214

207215
@pytest.mark.parametrize(
@@ -230,7 +238,7 @@ def test_skipif_false(
230238
assert "1 failure in tests" in sphinx_output
231239
plugin_output.fnmatch_lines(["*=== 1 failed in *"])
232240
else:
233-
assert "1 items passed all tests" in sphinx_output
241+
assert_1_item_passed(sphinx_output)
234242
plugin_output.fnmatch_lines(["*=== 1 passed in *"])
235243

236244
@pytest.mark.parametrize("wrong_output_assertion", [True, False])
@@ -272,7 +280,7 @@ def test_skipif_multiple_testoutput(
272280
assert "1 failure in tests" in sphinx_output
273281
plugin_output.fnmatch_lines(["*=== 1 failed in *"])
274282
else:
275-
assert "1 items passed all tests" in sphinx_output
283+
assert_1_item_passed(sphinx_output)
276284
plugin_output.fnmatch_lines(["*=== 1 passed in *"])
277285

278286
@pytest.mark.parametrize("testcode", ["raise RuntimeError", "pass", "print(1234)"])

0 commit comments

Comments
 (0)