11from __future__ import annotations
22
3- import tempfile
43from collections .abc import Generator
4+ from pathlib import Path
55
66import pytest
77from _pytest .fixtures import SubRequest
88
9+ from pydocstringformatter import _formatting
910from pydocstringformatter import _testutils as test_utils
1011from pydocstringformatter ._utils import UnstableResultError
1112from pydocstringformatter .run import _Run
1213
1314
1415@pytest .fixture (scope = "function" )
15- def patched_run (request : SubRequest ) -> Generator [Type [_Run ], None , None ]:
16+ def patched_run (request : SubRequest ) -> Generator [type [_Run ], None , None ]:
1617 """Patches the _Run class to use the MakeAFormatter and MakeBFormatter."""
1718 # This monkeypatches the formatters to make them conflict.
1819 # and the only formatters applied
19- # pylint: disable=wrong-import-position, import-outside-toplevel
20- from pydocstringformatter import _formatting # noqa: E402
2120
2221 old_formatters = _formatting .FORMATTERS
2322 _formatting .FORMATTERS = request .param
@@ -26,9 +25,8 @@ def cleanup() -> None:
2625 """Returns the formatters to their original state."""
2726 _formatting .FORMATTERS = old_formatters
2827
29- request .addfinalizer (cleanup )
30-
3128 yield _Run
29+ cleanup ()
3230
3331
3432@pytest .mark .parametrize (
@@ -54,20 +52,20 @@ def cleanup() -> None:
5452 indirect = ["patched_run" ],
5553)
5654def test_conflicting_formatters (
57- patched_run : Type [_Run ], # pylint: disable=redefined-outer-name
58- expect_errors : List [str ],
55+ patched_run : type [_Run ], # pylint: disable=redefined-outer-name
56+ expect_errors : list [str ],
57+ tmp_path : Path ,
5958) -> None :
6059 """Tests that conflicting formatters raise an error."""
61- with tempfile .TemporaryDirectory () as tmp :
62- tmp_file = tmp + "/test.py"
63- with open (tmp_file , "w" , encoding = "utf-8" ) as f :
64- content = [
65- '"""AAA AA AAA"""' ,
66- ]
67- f .writelines (content )
60+ tmp_file = tmp_path / "test.py"
61+ with open (tmp_file , "w" , encoding = "utf-8" ) as f :
62+ content = [
63+ '"""AAA AA AAA"""' ,
64+ ]
65+ f .writelines (content )
6866
69- with pytest .raises (UnstableResultError ) as err :
70- patched_run ([tmp_file ])
67+ with pytest .raises (UnstableResultError ) as err :
68+ patched_run ([str ( tmp_file ) ])
7169
72- for expect_err in expect_errors :
73- assert expect_err in str (err .value ), str (err .value )
70+ for expect_err in expect_errors :
71+ assert expect_err in str (err .value ), str (err .value )
0 commit comments