From 9d37e3ced2a78f9e193c3fbee51e048f373644df Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Fri, 19 Jul 2019 19:59:53 -0400 Subject: [PATCH] Remove rmtree from tests.lib.path.Path. --- tests/functional/test_install.py | 2 +- tests/lib/__init__.py | 7 +++++-- tests/lib/path.py | 6 ------ tests/lib/venv.py | 3 ++- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 3a945710e..96b780f3c 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -115,7 +115,7 @@ def test_pep518_with_user_pip(script, pip_src, data, common_wheels): script.pip("install", "--ignore-installed", "-f", common_wheels, "--user", pip_src) system_pip_dir = script.site_packages_path / 'pip' - system_pip_dir.rmtree() + assert not system_pip_dir.exists() system_pip_dir.mkdir() with open(system_pip_dir / '__init__.py', 'w') as fp: fp.write('raise ImportError\n') diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index ca0d0c37d..0cfd56956 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -139,7 +139,10 @@ class TestData(object): return obj def reset(self): - self.root.rmtree() + # Check explicitly for the target directory to avoid overly-broad + # try/except. + if self.root.exists(): + shutil.rmtree(self.root) self.source.copytree(self.root) @property @@ -948,7 +951,7 @@ def create_basic_wheel_for_package(script, name, version, generated = shutil.make_archive(retval, 'zip', script.temp_path) shutil.move(generated, retval) - script.temp_path.rmtree() + shutil.rmtree(script.temp_path) script.temp_path.mkdir() return retval diff --git a/tests/lib/path.py b/tests/lib/path.py index f59bb71ad..fec23d7a8 100644 --- a/tests/lib/path.py +++ b/tests/lib/path.py @@ -186,12 +186,6 @@ class Path(_base): """ return os.rmdir(self) - def rmtree(self, noerrors=True): - """ - Removes a directory tree. Ignores errors by default. - """ - return shutil.rmtree(self, ignore_errors=noerrors) - def copy(self, to): return shutil.copy(self, to) diff --git a/tests/lib/venv.py b/tests/lib/venv.py index ba456785d..609989f6f 100644 --- a/tests/lib/venv.py +++ b/tests/lib/venv.py @@ -1,6 +1,7 @@ from __future__ import absolute_import import compileall +import shutil import sys import textwrap @@ -47,7 +48,7 @@ class VirtualEnvironment(object): def _create(self, clear=False): if clear: - self.location.rmtree() + shutil.rmtree(self.location) if self._template: # On Windows, calling `_virtualenv.path_locations(target)` # will have created the `target` directory...