66
77import pytest
88from _pytest import pathlib
9+ from _pytest .pathlib import cleanup_numbered_dir
10+ from _pytest .pathlib import create_cleanup_lock
11+ from _pytest .pathlib import make_numbered_dir
12+ from _pytest .pathlib import maybe_delete_a_numbered_dir
13+ from _pytest .pathlib import on_rm_rf_error
914from _pytest .pathlib import Path
15+ from _pytest .pathlib import register_cleanup_lock_removal
16+ from _pytest .pathlib import rm_rf
17+ from _pytest .tmpdir import get_user
18+ from _pytest .tmpdir import TempdirFactory
19+ from _pytest .tmpdir import TempPathFactory
1020
1121
1222def test_tmpdir_fixture (testdir ):
@@ -33,9 +43,6 @@ def option(self):
3343
3444class TestTempdirHandler :
3545 def test_mktemp (self , tmp_path ):
36-
37- from _pytest .tmpdir import TempdirFactory , TempPathFactory
38-
3946 config = FakeConfig (tmp_path )
4047 t = TempdirFactory (TempPathFactory .from_config (config ))
4148 tmp = t .mktemp ("world" )
@@ -48,8 +55,6 @@ def test_mktemp(self, tmp_path):
4855
4956 def test_tmppath_relative_basetemp_absolute (self , tmp_path , monkeypatch ):
5057 """#4425"""
51- from _pytest .tmpdir import TempPathFactory
52-
5358 monkeypatch .chdir (tmp_path )
5459 config = FakeConfig ("hello" )
5560 t = TempPathFactory .from_config (config )
@@ -91,7 +96,6 @@ def test_mktemp(testdir, basename, is_ok):
9196 mytemp = testdir .tmpdir .mkdir ("mytemp" )
9297 p = testdir .makepyfile (
9398 """
94- import pytest
9599 def test_abs_path(tmpdir_factory):
96100 tmpdir_factory.mktemp('{}', numbered=False)
97101 """ .format (
@@ -181,7 +185,6 @@ def test_tmpdir_fallback_tox_env(testdir, monkeypatch):
181185 monkeypatch .delenv ("USERNAME" , raising = False )
182186 testdir .makepyfile (
183187 """
184- import pytest
185188 def test_some(tmpdir):
186189 assert tmpdir.isdir()
187190 """
@@ -207,7 +210,6 @@ def test_tmpdir_fallback_uid_not_found(testdir):
207210
208211 testdir .makepyfile (
209212 """
210- import pytest
211213 def test_some(tmpdir):
212214 assert tmpdir.isdir()
213215 """
@@ -223,8 +225,6 @@ def test_get_user_uid_not_found():
223225 user id does not correspond to a valid user (e.g. running pytest in a
224226 Docker container with 'docker run -u'.
225227 """
226- from _pytest .tmpdir import get_user
227-
228228 assert get_user () is None
229229
230230
@@ -234,8 +234,6 @@ def test_get_user(monkeypatch):
234234 required by getpass module are missing from the environment on Windows
235235 (#1010).
236236 """
237- from _pytest .tmpdir import get_user
238-
239237 monkeypatch .delenv ("USER" , raising = False )
240238 monkeypatch .delenv ("USERNAME" , raising = False )
241239 assert get_user () is None
@@ -245,8 +243,6 @@ class TestNumberedDir:
245243 PREFIX = "fun-"
246244
247245 def test_make (self , tmp_path ):
248- from _pytest .pathlib import make_numbered_dir
249-
250246 for i in range (10 ):
251247 d = make_numbered_dir (root = tmp_path , prefix = self .PREFIX )
252248 assert d .name .startswith (self .PREFIX )
@@ -261,17 +257,13 @@ def test_make(self, tmp_path):
261257 def test_cleanup_lock_create (self , tmp_path ):
262258 d = tmp_path .joinpath ("test" )
263259 d .mkdir ()
264- from _pytest .pathlib import create_cleanup_lock
265-
266260 lockfile = create_cleanup_lock (d )
267261 with pytest .raises (OSError , match = "cannot create lockfile in .*" ):
268262 create_cleanup_lock (d )
269263
270264 lockfile .unlink ()
271265
272266 def test_lock_register_cleanup_removal (self , tmp_path ):
273- from _pytest .pathlib import create_cleanup_lock , register_cleanup_lock_removal
274-
275267 lock = create_cleanup_lock (tmp_path )
276268
277269 registry = []
@@ -295,8 +287,6 @@ def test_lock_register_cleanup_removal(self, tmp_path):
295287
296288 def _do_cleanup (self , tmp_path ):
297289 self .test_make (tmp_path )
298- from _pytest .pathlib import cleanup_numbered_dir
299-
300290 cleanup_numbered_dir (
301291 root = tmp_path ,
302292 prefix = self .PREFIX ,
@@ -310,12 +300,9 @@ def test_cleanup_keep(self, tmp_path):
310300 print (a , b )
311301
312302 def test_cleanup_locked (self , tmp_path ):
303+ p = make_numbered_dir (root = tmp_path , prefix = self .PREFIX )
313304
314- from _pytest import pathlib
315-
316- p = pathlib .make_numbered_dir (root = tmp_path , prefix = self .PREFIX )
317-
318- pathlib .create_cleanup_lock (p )
305+ create_cleanup_lock (p )
319306
320307 assert not pathlib .ensure_deletable (
321308 p , consider_lock_dead_if_created_before = p .stat ().st_mtime - 1
@@ -330,16 +317,14 @@ def test_cleanup_ignores_symlink(self, tmp_path):
330317 self ._do_cleanup (tmp_path )
331318
332319 def test_removal_accepts_lock (self , tmp_path ):
333- folder = pathlib . make_numbered_dir (root = tmp_path , prefix = self .PREFIX )
334- pathlib . create_cleanup_lock (folder )
335- pathlib . maybe_delete_a_numbered_dir (folder )
320+ folder = make_numbered_dir (root = tmp_path , prefix = self .PREFIX )
321+ create_cleanup_lock (folder )
322+ maybe_delete_a_numbered_dir (folder )
336323 assert folder .is_dir ()
337324
338325
339326class TestRmRf :
340327 def test_rm_rf (self , tmp_path ):
341- from _pytest .pathlib import rm_rf
342-
343328 adir = tmp_path / "adir"
344329 adir .mkdir ()
345330 rm_rf (adir )
@@ -355,8 +340,6 @@ def test_rm_rf(self, tmp_path):
355340
356341 def test_rm_rf_with_read_only_file (self , tmp_path ):
357342 """Ensure rm_rf can remove directories with read-only files in them (#5524)"""
358- from _pytest .pathlib import rm_rf
359-
360343 fn = tmp_path / "dir/foo.txt"
361344 fn .parent .mkdir ()
362345
@@ -374,8 +357,6 @@ def chmod_r(self, path):
374357
375358 def test_rm_rf_with_read_only_directory (self , tmp_path ):
376359 """Ensure rm_rf can remove read-only directories (#5524)"""
377- from _pytest .pathlib import rm_rf
378-
379360 adir = tmp_path / "dir"
380361 adir .mkdir ()
381362
@@ -387,8 +368,6 @@ def test_rm_rf_with_read_only_directory(self, tmp_path):
387368 assert not adir .is_dir ()
388369
389370 def test_on_rm_rf_error (self , tmp_path ):
390- from _pytest .pathlib import on_rm_rf_error
391-
392371 adir = tmp_path / "dir"
393372 adir .mkdir ()
394373
0 commit comments