Skip to content

Commit 89b5bbe

Browse files
committed
Cleanup/move imports with tmpdir tests
1 parent 5d539af commit 89b5bbe

File tree

1 file changed

+14
-36
lines changed

1 file changed

+14
-36
lines changed

testing/test_tmpdir.py

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66

77
import pytest
88
from _pytest import pathlib
9+
from _pytest.pathlib import create_cleanup_lock
10+
from _pytest.pathlib import make_numbered_dir
11+
from _pytest.pathlib import maybe_delete_a_numbered_dir
12+
from _pytest.pathlib import on_rm_rf_error
913
from _pytest.pathlib import Path
14+
from _pytest.pathlib import register_cleanup_lock_removal
15+
from _pytest.pathlib import rm_rf
16+
from _pytest.tmpdir import get_user
17+
from _pytest.tmpdir import TempdirFactory
18+
from _pytest.tmpdir import TempPathFactory
1019

1120

1221
def test_tmpdir_fixture(testdir):
@@ -33,9 +42,6 @@ def option(self):
3342

3443
class TestTempdirHandler:
3544
def test_mktemp(self, tmp_path):
36-
37-
from _pytest.tmpdir import TempdirFactory, TempPathFactory
38-
3945
config = FakeConfig(tmp_path)
4046
t = TempdirFactory(TempPathFactory.from_config(config))
4147
tmp = t.mktemp("world")
@@ -48,8 +54,6 @@ def test_mktemp(self, tmp_path):
4854

4955
def test_tmppath_relative_basetemp_absolute(self, tmp_path, monkeypatch):
5056
"""#4425"""
51-
from _pytest.tmpdir import TempPathFactory
52-
5357
monkeypatch.chdir(tmp_path)
5458
config = FakeConfig("hello")
5559
t = TempPathFactory.from_config(config)
@@ -91,7 +95,6 @@ def test_mktemp(testdir, basename, is_ok):
9195
mytemp = testdir.tmpdir.mkdir("mytemp")
9296
p = testdir.makepyfile(
9397
"""
94-
import pytest
9598
def test_abs_path(tmpdir_factory):
9699
tmpdir_factory.mktemp('{}', numbered=False)
97100
""".format(
@@ -181,7 +184,6 @@ def test_tmpdir_fallback_tox_env(testdir, monkeypatch):
181184
monkeypatch.delenv("USERNAME", raising=False)
182185
testdir.makepyfile(
183186
"""
184-
import pytest
185187
def test_some(tmpdir):
186188
assert tmpdir.isdir()
187189
"""
@@ -207,7 +209,6 @@ def test_tmpdir_fallback_uid_not_found(testdir):
207209

208210
testdir.makepyfile(
209211
"""
210-
import pytest
211212
def test_some(tmpdir):
212213
assert tmpdir.isdir()
213214
"""
@@ -223,8 +224,6 @@ def test_get_user_uid_not_found():
223224
user id does not correspond to a valid user (e.g. running pytest in a
224225
Docker container with 'docker run -u'.
225226
"""
226-
from _pytest.tmpdir import get_user
227-
228227
assert get_user() is None
229228

230229

@@ -234,8 +233,6 @@ def test_get_user(monkeypatch):
234233
required by getpass module are missing from the environment on Windows
235234
(#1010).
236235
"""
237-
from _pytest.tmpdir import get_user
238-
239236
monkeypatch.delenv("USER", raising=False)
240237
monkeypatch.delenv("USERNAME", raising=False)
241238
assert get_user() is None
@@ -245,8 +242,6 @@ class TestNumberedDir:
245242
PREFIX = "fun-"
246243

247244
def test_make(self, tmp_path):
248-
from _pytest.pathlib import make_numbered_dir
249-
250245
for i in range(10):
251246
d = make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
252247
assert d.name.startswith(self.PREFIX)
@@ -261,17 +256,13 @@ def test_make(self, tmp_path):
261256
def test_cleanup_lock_create(self, tmp_path):
262257
d = tmp_path.joinpath("test")
263258
d.mkdir()
264-
from _pytest.pathlib import create_cleanup_lock
265-
266259
lockfile = create_cleanup_lock(d)
267260
with pytest.raises(OSError, match="cannot create lockfile in .*"):
268261
create_cleanup_lock(d)
269262

270263
lockfile.unlink()
271264

272265
def test_lock_register_cleanup_removal(self, tmp_path):
273-
from _pytest.pathlib import create_cleanup_lock, register_cleanup_lock_removal
274-
275266
lock = create_cleanup_lock(tmp_path)
276267

277268
registry = []
@@ -295,8 +286,6 @@ def test_lock_register_cleanup_removal(self, tmp_path):
295286

296287
def _do_cleanup(self, tmp_path):
297288
self.test_make(tmp_path)
298-
from _pytest.pathlib import cleanup_numbered_dir
299-
300289
cleanup_numbered_dir(
301290
root=tmp_path,
302291
prefix=self.PREFIX,
@@ -310,12 +299,9 @@ def test_cleanup_keep(self, tmp_path):
310299
print(a, b)
311300

312301
def test_cleanup_locked(self, tmp_path):
302+
p = make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
313303

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)
304+
create_cleanup_lock(p)
319305

320306
assert not pathlib.ensure_deletable(
321307
p, consider_lock_dead_if_created_before=p.stat().st_mtime - 1
@@ -330,16 +316,14 @@ def test_cleanup_ignores_symlink(self, tmp_path):
330316
self._do_cleanup(tmp_path)
331317

332318
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)
319+
folder = make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
320+
create_cleanup_lock(folder)
321+
maybe_delete_a_numbered_dir(folder)
336322
assert folder.is_dir()
337323

338324

339325
class TestRmRf:
340326
def test_rm_rf(self, tmp_path):
341-
from _pytest.pathlib import rm_rf
342-
343327
adir = tmp_path / "adir"
344328
adir.mkdir()
345329
rm_rf(adir)
@@ -355,8 +339,6 @@ def test_rm_rf(self, tmp_path):
355339

356340
def test_rm_rf_with_read_only_file(self, tmp_path):
357341
"""Ensure rm_rf can remove directories with read-only files in them (#5524)"""
358-
from _pytest.pathlib import rm_rf
359-
360342
fn = tmp_path / "dir/foo.txt"
361343
fn.parent.mkdir()
362344

@@ -374,8 +356,6 @@ def chmod_r(self, path):
374356

375357
def test_rm_rf_with_read_only_directory(self, tmp_path):
376358
"""Ensure rm_rf can remove read-only directories (#5524)"""
377-
from _pytest.pathlib import rm_rf
378-
379359
adir = tmp_path / "dir"
380360
adir.mkdir()
381361

@@ -387,8 +367,6 @@ def test_rm_rf_with_read_only_directory(self, tmp_path):
387367
assert not adir.is_dir()
388368

389369
def test_on_rm_rf_error(self, tmp_path):
390-
from _pytest.pathlib import on_rm_rf_error
391-
392370
adir = tmp_path / "dir"
393371
adir.mkdir()
394372

0 commit comments

Comments
 (0)