Skip to content

Commit

Permalink
Remove mlruns directory in module teardown (#5120)
Browse files Browse the repository at this point in the history
* Remove mlruns directory in module teardown

Signed-off-by: harupy <hkawamura0130@gmail.com>

* fix docstring

Signed-off-by: harupy <hkawamura0130@gmail.com>

* remove if exists

Signed-off-by: harupy <hkawamura0130@gmail.com>

* try onerror

Signed-off-by: harupy <hkawamura0130@gmail.com>

* try sudo

Signed-off-by: harupy <hkawamura0130@gmail.com>

* skip clean up on CI

Signed-off-by: harupy <hkawamura0130@gmail.com>
  • Loading branch information
harupy committed Nov 30, 2021
1 parent c296fc4 commit db52c8e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/conftest.py
@@ -1,5 +1,7 @@
import os
import inspect
import shutil
import subprocess
from unittest import mock

import pytest
Expand Down Expand Up @@ -96,3 +98,25 @@ def new_exception(msg, *_, **__):
yield
else:
yield


@pytest.fixture(autouse=True, scope="module")
def clean_up_mlruns_direcotry(request):
"""
Clean up an `mlruns` directory on each test module teardown on CI to save the disk space.
"""
yield

# Only run this fixture on CI.
if "GITHUB_ACTIONS" not in os.environ:
return

mlruns_dir = os.path.join(request.config.rootpath, "mlruns")
if os.path.exists(mlruns_dir):
try:
shutil.rmtree(mlruns_dir)
except IOError:
if os.name == "nt":
raise
# `shutil.rmtree` can't remove files owned by root in a docker container.
subprocess.run(["sudo", "rm", "-rf", mlruns_dir], check=True)

0 comments on commit db52c8e

Please sign in to comment.