22import os
33import re
44import shlex
5- import shutil
65import subprocess
76import sys
8- import tempfile
97import time
108from enum import Enum
119from pathlib import Path
@@ -190,7 +188,7 @@ def get_testdir():
190188
191189@pytest .fixture (scope = "session" )
192190def test_session_tmpdir (tmp_path_factory ) -> Path :
193- tmpdir = tmp_path_factory .mktemp ("bash-completion-test_ " )
191+ tmpdir = tmp_path_factory .mktemp ("bash-completion.session. " )
194192
195193 user_dir_1 = tmpdir / "bash-completion"
196194 user_dir_2 = tmpdir / "bash-completion-fallback"
@@ -231,9 +229,8 @@ def test_session_tmpdir(tmp_path_factory) -> Path:
231229
232230
233231@pytest .fixture (scope = "class" )
234- def bash (request , test_session_tmpdir ) -> pexpect .spawn :
232+ def bash (request , test_session_tmpdir , tmp_path_factory ) -> pexpect .spawn :
235233 logfile : Optional [TextIO ] = None
236- tmpdir = None
237234 bash = None
238235
239236 if os .environ .get ("BASH_COMPLETION_TEST_LOGFILE" ):
@@ -268,10 +265,8 @@ def bash(request, test_session_tmpdir) -> pexpect.spawn:
268265 testdir , "fixtures" , marker .kwargs .get ("cwd" )
269266 )
270267 elif "temp_cwd" in marker .kwargs and marker .kwargs .get ("temp_cwd" ):
271- tmpdir = tempfile .TemporaryDirectory (
272- prefix = "bash-completion-test_"
273- )
274- cwd = tmpdir .name
268+ tmpdir = tmp_path_factory .mktemp ("bash-completion.bash." )
269+ cwd = str (tmpdir )
275270 if cwd is None :
276271 cwd = os .path .join (testdir , "fixtures" )
277272 os .chdir (cwd )
@@ -371,8 +366,6 @@ def bash(request, test_session_tmpdir) -> pexpect.spawn:
371366 # Clean up
372367 if bash :
373368 bash .close ()
374- if tmpdir :
375- tmpdir .cleanup ()
376369 if logfile and logfile != sys .stdout :
377370 logfile .close ()
378371
@@ -961,7 +954,7 @@ def in_container() -> bool:
961954
962955
963956def prepare_fixture_dir (
964- request , files : Iterable [str ], dirs : Iterable [str ]
957+ tmp_path_factory , files : Iterable [str ], dirs : Iterable [str ]
965958) -> Path :
966959 """
967960 Fixture to prepare a test dir with dummy contents on the fly.
@@ -970,8 +963,7 @@ def prepare_fixture_dir(
970963 prepare a dir on the fly rather than including their fixtures in git and
971964 the tarball. This is to work better with case insensitive file systems.
972965 """
973- tempdir = Path (tempfile .mkdtemp (prefix = "bash-completion-fixture-dir" ))
974- request .addfinalizer (lambda : shutil .rmtree (str (tempdir )))
966+ tempdir = tmp_path_factory .mktemp ("bash-completion.fixture_dir." )
975967
976968 old_cwd = os .getcwd ()
977969 try :
0 commit comments