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

fix(ci): make test of dataset stable #1592

Merged
merged 2 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions client/starwhale/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ def ensure_file(
os.chmod(path, mode)


def empty_dir(p: t.Union[str, Path]) -> None:
def empty_dir(
p: t.Union[str, Path],
ignore_errors: bool = False,
onerror: t.Optional[t.Callable] = None,
) -> None:
if not p:
return

Expand All @@ -55,7 +59,7 @@ def empty_dir(p: t.Union[str, Path]) -> None:

def _self_empty() -> None:
if path.is_dir():
shutil.rmtree(str(path.resolve()))
shutil.rmtree(str(path.resolve()), ignore_errors, onerror)
else:
path.unlink()

Expand Down
3 changes: 2 additions & 1 deletion client/tests/sdk/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def setUp(self) -> None:
self.mock_atexit.start()

def tearDown(self) -> None:
empty_dir(self.local_storage)
# use ignore_errors = True to prevent errors like "Directory not empty" caused by missing close action in test
empty_dir(self.local_storage, ignore_errors=True)
os.environ.pop(ENV_SW_CLI_CONFIG, "")
os.environ.pop(ENV_SW_LOCAL_STORAGE, "")

Expand Down