Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mlruns directory in module teardown #5120

Merged
merged 6 commits into from Nov 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)