From fc39ec92205ceb13f3b79bc31dbdf4f4cfe190f0 Mon Sep 17 00:00:00 2001 From: harupy Date: Tue, 30 Nov 2021 01:31:14 +0900 Subject: [PATCH] use sudo Signed-off-by: harupy --- tests/conftest.py | 8 +------- tests/projects/test_docker_projects.py | 10 +++++++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1f736633180b2..b3b213c85a4eb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,4 @@ import os -import stat import inspect import shutil from unittest import mock @@ -100,11 +99,6 @@ def new_exception(msg, *_, **__): yield -def on_rm_error(func, path, exc_info): # pylint: disable=unused-argument - os.chmod(path, stat.S_IWRITE) - os.unlink(path) - - @pytest.fixture(autouse=True, scope="module") def clean_up_mlruns_direcotry(request): """ @@ -113,4 +107,4 @@ def clean_up_mlruns_direcotry(request): yield mlruns_dir = os.path.join(request.config.rootpath, "mlruns") if os.path.exists(mlruns_dir): - shutil.rmtree(mlruns_dir, onerror=on_rm_error) + shutil.rmtree(mlruns_dir) diff --git a/tests/projects/test_docker_projects.py b/tests/projects/test_docker_projects.py index 813546ac6455b..1a39b29456df3 100644 --- a/tests/projects/test_docker_projects.py +++ b/tests/projects/test_docker_projects.py @@ -1,8 +1,8 @@ import os import pytest -import posixpath # pylint: disable=unused-import from unittest import mock +import subprocess from databricks_cli.configure.provider import DatabricksConfig @@ -24,6 +24,14 @@ from mlflow.exceptions import MlflowException +@pytest.fixture(autouse=True, scope="module") +def clean_up_mlruns_direcotry(request): + yield + mlruns_dir = os.path.join(request.config.rootpath, "mlruns") + # Use `sudo` to forcibly remove files created in a docker container + subprocess.run(["sudo", "rm", "-rf", mlruns_dir], check=True) + + def _build_uri(base_uri, subdirectory): if subdirectory != "": return "%s#%s" % (base_uri, subdirectory)