1111from packaging .specifiers import InvalidSpecifier
1212from packaging .version import InvalidVersion
1313
14- from sphinx .ext .doctest import is_allowed_version
14+ from sphinx .ext .doctest import DocTestBuilder , is_allowed_version
1515
1616if TYPE_CHECKING :
1717 from sphinx .testing .util import SphinxTestApp
@@ -74,12 +74,12 @@ def test_is_allowed_version() -> None:
7474 is_allowed_version ('>3.4' , 'Sphinx' )
7575
7676
77- def cleanup_call ():
77+ def cleanup_call () -> None :
7878 global cleanup_called # NoQA: PLW0603
7979 cleanup_called += 1
8080
8181
82- recorded_calls : Counter [tuple [str , str , int ]] = Counter ()
82+ recorded_calls : Counter [tuple [str , str , bool ]] = Counter ()
8383
8484
8585@pytest .mark .sphinx ('doctest' , testroot = 'ext-doctest-skipif' )
@@ -125,16 +125,17 @@ def test_skipif(app: SphinxTestApp) -> None:
125125 }
126126
127127
128- def record (directive , part , should_skip ) :
128+ def record (directive : str , part : str , should_skip : bool ) -> str :
129129 recorded_calls [directive , part , should_skip ] += 1
130130 return f'Recorded { directive } { part } { should_skip } '
131131
132132
133133@pytest .mark .sphinx ('doctest' , testroot = 'ext-doctest-with-autodoc' )
134- def test_reporting_with_autodoc (app , capfd ) :
134+ def test_reporting_with_autodoc (app : SphinxTestApp ) -> None :
135135 # Patch builder to get a copy of the output
136- written = []
137- app .builder ._warn_out = written .append
136+ written : list [str ] = []
137+ assert isinstance (app .builder , DocTestBuilder )
138+ app .builder ._warn_out = written .append # type: ignore[method-assign]
138139 app .build (force_all = True )
139140
140141 failures = [
@@ -151,36 +152,43 @@ def test_reporting_with_autodoc(app, capfd):
151152
152153@pytest .mark .sphinx ('doctest' , testroot = 'ext-doctest-fail-fast' )
153154@pytest .mark .parametrize ('fail_fast' , [False , True , None ])
154- def test_fail_fast (app , fail_fast , capsys ) :
155+ def test_fail_fast (app : SphinxTestApp , fail_fast : bool | None ) -> None :
155156 if fail_fast is not None :
156157 app .config .doctest_fail_fast = fail_fast
157158 # Patch builder to get a copy of the output
158- written = []
159- app .builder ._out = written .append
159+ written : list [str ] = []
160+ assert isinstance (app .builder , DocTestBuilder )
161+ app .builder ._out = written .append # type: ignore[method-assign]
160162 app .build (force_all = True )
161163 assert app .statuscode
162164
163- written = '' .join (written )
165+ written = '' .join (written ). split ( ' \n ' )
164166 if fail_fast :
165- assert 'Doctest summary (exiting after first failed test)' in written
166- assert ' 1 failure in tests' in written
167+ assert written [ 10 ] == 'Doctest summary (exiting after first failed test)'
168+ assert written [ 13 ] == ' 1 failure in tests'
167169 else :
168- assert 'Doctest summary\n ' in written
169- assert ' 2 failures in tests' in written
170+ assert written [ 10 ] == 'Doctest summary'
171+ assert written [ 13 ] == ' 2 failures in tests'
170172
171173
172174@pytest .mark .sphinx ('doctest' , testroot = 'ext-doctest-with-autodoc' )
173175@pytest .mark .parametrize (
174176 ('test_doctest_blocks' , 'group_name' ),
175- [(None , 'default' ), ('CustomGroupName' , 'CustomGroupName' )],
177+ [
178+ (None , 'default' ),
179+ ('CustomGroupName' , 'CustomGroupName' ),
180+ ],
176181)
177- def test_doctest_block_group_name (app , test_doctest_blocks , group_name , capfd ):
182+ def test_doctest_block_group_name (
183+ app : SphinxTestApp , test_doctest_blocks : str | None , group_name : str
184+ ) -> None :
178185 if test_doctest_blocks is not None :
179186 app .config .doctest_test_doctest_blocks = test_doctest_blocks
180187
181188 # Patch builder to get a copy of the output
182- written = []
183- app .builder ._warn_out = written .append
189+ written : list [str ] = []
190+ assert isinstance (app .builder , DocTestBuilder )
191+ app .builder ._warn_out = written .append # type: ignore[method-assign]
184192 app .build (force_all = True )
185193
186194 failures = [
0 commit comments