-
Notifications
You must be signed in to change notification settings - Fork 7
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
Clean up macOS test apps on failure #117
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more pytest-native to use a fixture to have pre and post-run cleanup tasks: https://docs.pytest.org/en/stable/how-to/fixtures.html#yield-fixtures-recommended
A fixture you could use for example (untested):
# If the test app already exists, this test will fail,
# so clean up before and after the run.
def _clean_macos_apps(shortcuts: list[Path]):
if not sys.platform == "darwin":
return
for shortcut in shortcuts:
if shortcut.exists():
shutil.rmtree(shortcut)
@pytest.fixture
def clean_shortcuts(tmp_path: Path, shortcut_path: dict[str, str]):
# The shortcut will take 'root_prefix' as the base, but conda-standalone
# sets that to its temporary 'sys.prefix' as provided by the pyinstaller
# self-extraction. We override it via 'CONDA_ROOT_PREFIX' in the same
# way 'constructor' will do it.
variables = {"base": Path(sys.prefix).name, "name": tmp_path.name}
shortcuts = [
folder / shortcut_path[sys.platform].format(**variables)
for folder in _get_shortcut_dirs()
]
_clean_macos_apps(shortcuts)
yield {"tmp_path": tmp_path, "shortcuts": shortcuts}
_clean_macos_apps(shortcuts)
Please also stop importing conftest since this is just a pytest configuration module, not a regular Python module to store test tools or configuration in. Simply convert the values there into pytest fixtures, which will make the tests a lot more resilient to test reordering.
I created that fixture, but I'm not sure I like the solution. The problem is the conda-standalone/tests/test_uninstall.py Lines 251 to 254 in 5a3ee82
This makes the fixture a little limited. |
Description
If the test apps of the test package already exist, the menuinst tests will fail. If there is an
AssertionError
in these tests, the files are currently not cleaned up either.Checklist - did you ...
news
directory (using the template) for the next release's release notes?