6
6
7
7
import pytest
8
8
from _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
9
14
from _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
10
20
11
21
12
22
def test_tmpdir_fixture (testdir ):
@@ -33,9 +43,6 @@ def option(self):
33
43
34
44
class TestTempdirHandler :
35
45
def test_mktemp (self , tmp_path ):
36
-
37
- from _pytest .tmpdir import TempdirFactory , TempPathFactory
38
-
39
46
config = FakeConfig (tmp_path )
40
47
t = TempdirFactory (TempPathFactory .from_config (config ))
41
48
tmp = t .mktemp ("world" )
@@ -48,8 +55,6 @@ def test_mktemp(self, tmp_path):
48
55
49
56
def test_tmppath_relative_basetemp_absolute (self , tmp_path , monkeypatch ):
50
57
"""#4425"""
51
- from _pytest .tmpdir import TempPathFactory
52
-
53
58
monkeypatch .chdir (tmp_path )
54
59
config = FakeConfig ("hello" )
55
60
t = TempPathFactory .from_config (config )
@@ -91,7 +96,6 @@ def test_mktemp(testdir, basename, is_ok):
91
96
mytemp = testdir .tmpdir .mkdir ("mytemp" )
92
97
p = testdir .makepyfile (
93
98
"""
94
- import pytest
95
99
def test_abs_path(tmpdir_factory):
96
100
tmpdir_factory.mktemp('{}', numbered=False)
97
101
""" .format (
@@ -181,7 +185,6 @@ def test_tmpdir_fallback_tox_env(testdir, monkeypatch):
181
185
monkeypatch .delenv ("USERNAME" , raising = False )
182
186
testdir .makepyfile (
183
187
"""
184
- import pytest
185
188
def test_some(tmpdir):
186
189
assert tmpdir.isdir()
187
190
"""
@@ -207,7 +210,6 @@ def test_tmpdir_fallback_uid_not_found(testdir):
207
210
208
211
testdir .makepyfile (
209
212
"""
210
- import pytest
211
213
def test_some(tmpdir):
212
214
assert tmpdir.isdir()
213
215
"""
@@ -223,8 +225,6 @@ def test_get_user_uid_not_found():
223
225
user id does not correspond to a valid user (e.g. running pytest in a
224
226
Docker container with 'docker run -u'.
225
227
"""
226
- from _pytest .tmpdir import get_user
227
-
228
228
assert get_user () is None
229
229
230
230
@@ -234,8 +234,6 @@ def test_get_user(monkeypatch):
234
234
required by getpass module are missing from the environment on Windows
235
235
(#1010).
236
236
"""
237
- from _pytest .tmpdir import get_user
238
-
239
237
monkeypatch .delenv ("USER" , raising = False )
240
238
monkeypatch .delenv ("USERNAME" , raising = False )
241
239
assert get_user () is None
@@ -245,8 +243,6 @@ class TestNumberedDir:
245
243
PREFIX = "fun-"
246
244
247
245
def test_make (self , tmp_path ):
248
- from _pytest .pathlib import make_numbered_dir
249
-
250
246
for i in range (10 ):
251
247
d = make_numbered_dir (root = tmp_path , prefix = self .PREFIX )
252
248
assert d .name .startswith (self .PREFIX )
@@ -261,17 +257,13 @@ def test_make(self, tmp_path):
261
257
def test_cleanup_lock_create (self , tmp_path ):
262
258
d = tmp_path .joinpath ("test" )
263
259
d .mkdir ()
264
- from _pytest .pathlib import create_cleanup_lock
265
-
266
260
lockfile = create_cleanup_lock (d )
267
261
with pytest .raises (OSError , match = "cannot create lockfile in .*" ):
268
262
create_cleanup_lock (d )
269
263
270
264
lockfile .unlink ()
271
265
272
266
def test_lock_register_cleanup_removal (self , tmp_path ):
273
- from _pytest .pathlib import create_cleanup_lock , register_cleanup_lock_removal
274
-
275
267
lock = create_cleanup_lock (tmp_path )
276
268
277
269
registry = []
@@ -295,8 +287,6 @@ def test_lock_register_cleanup_removal(self, tmp_path):
295
287
296
288
def _do_cleanup (self , tmp_path ):
297
289
self .test_make (tmp_path )
298
- from _pytest .pathlib import cleanup_numbered_dir
299
-
300
290
cleanup_numbered_dir (
301
291
root = tmp_path ,
302
292
prefix = self .PREFIX ,
@@ -310,12 +300,9 @@ def test_cleanup_keep(self, tmp_path):
310
300
print (a , b )
311
301
312
302
def test_cleanup_locked (self , tmp_path ):
303
+ p = make_numbered_dir (root = tmp_path , prefix = self .PREFIX )
313
304
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 )
319
306
320
307
assert not pathlib .ensure_deletable (
321
308
p , consider_lock_dead_if_created_before = p .stat ().st_mtime - 1
@@ -330,16 +317,14 @@ def test_cleanup_ignores_symlink(self, tmp_path):
330
317
self ._do_cleanup (tmp_path )
331
318
332
319
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 )
336
323
assert folder .is_dir ()
337
324
338
325
339
326
class TestRmRf :
340
327
def test_rm_rf (self , tmp_path ):
341
- from _pytest .pathlib import rm_rf
342
-
343
328
adir = tmp_path / "adir"
344
329
adir .mkdir ()
345
330
rm_rf (adir )
@@ -355,8 +340,6 @@ def test_rm_rf(self, tmp_path):
355
340
356
341
def test_rm_rf_with_read_only_file (self , tmp_path ):
357
342
"""Ensure rm_rf can remove directories with read-only files in them (#5524)"""
358
- from _pytest .pathlib import rm_rf
359
-
360
343
fn = tmp_path / "dir/foo.txt"
361
344
fn .parent .mkdir ()
362
345
@@ -374,8 +357,6 @@ def chmod_r(self, path):
374
357
375
358
def test_rm_rf_with_read_only_directory (self , tmp_path ):
376
359
"""Ensure rm_rf can remove read-only directories (#5524)"""
377
- from _pytest .pathlib import rm_rf
378
-
379
360
adir = tmp_path / "dir"
380
361
adir .mkdir ()
381
362
@@ -387,8 +368,6 @@ def test_rm_rf_with_read_only_directory(self, tmp_path):
387
368
assert not adir .is_dir ()
388
369
389
370
def test_on_rm_rf_error (self , tmp_path ):
390
- from _pytest .pathlib import on_rm_rf_error
391
-
392
371
adir = tmp_path / "dir"
393
372
adir .mkdir ()
394
373
0 commit comments