Skip to content

Commit

Permalink
No error on test cleanup in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Nov 3, 2023
1 parent 33fa9fe commit 1cef2af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
14 changes: 11 additions & 3 deletions micromamba/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ def tmp_home(

# Pytest would clean it automatically but this can be large (0.5 Gb for repodata)
# We clean it explicitly
on_ci = "CI" in os.environ
if not request.config.getoption("--no-eager-clean"):
try:
helpers.rmtree(new_home)
except PermissionError:
pass
# Silence possible cleanup exeptions on CI, weird things happening there
except Exception as e:
if not on_ci:
raise e


@pytest.fixture
Expand Down Expand Up @@ -148,9 +151,14 @@ def tmp_root_prefix(

# Pytest would clean it automatically but this can be large (0.5 Gb for repodata)
# We clean it explicitly
on_ci = "CI" in os.environ
if not request.config.getoption("--no-eager-clean"):
if new_root_prefix.exists():
try:
helpers.rmtree(new_root_prefix)
# Silence possible cleanup exeptions on CI, weird things happening there
except Exception as e:
if not on_ci:
raise e
# os.environ restored by tmp_clean_env and tmp_environ


Expand Down
20 changes: 12 additions & 8 deletions micromamba/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,21 @@ def recursive_chmod(path: Path, permission, is_root=True):


def rmtree(path: Path):
p = Path(path)
recursive_chmod(p, 0o700)
path = Path(path)

def handleError(func, path, exc_info):
recursive_chmod(path, 0o700)
func(path)
if not path.exists():
return

if p.is_dir():
shutil.rmtree(p, onerror=handleError)
recursive_chmod(path, 0o700)

def handleError(func, p, exc_info):
recursive_chmod(p, 0o700)
func(p)

if path.is_dir():
shutil.rmtree(path, onerror=handleError)
else:
os.remove(p)
os.remove(path)


def get_fake_activate(prefix):
Expand Down

0 comments on commit 1cef2af

Please sign in to comment.