-
Notifications
You must be signed in to change notification settings - Fork 11
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
cleanup tests after run #65
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.
I had no idea hatch envs were so hungry. Thanks for discovering that.
tests/conftest.py
Outdated
|
||
yield | ||
|
||
shutil.rmtree(hatch_dir, ignore_errors=True) |
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.
Should this be wrapped in a try, finally?
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 can be if you'd like!
ignore_errors
makes the onexc
call here be just a pass
, so it handles these errors: https://github.com/python/cpython/blob/43447cb63421fb4db5411c1e74bdd8a4cfcf9263/Lib/shutil.py#L670-740
but if you'd like to add a catchall here i don't see the harm in that
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.
I meant
try:
yield
finally:
shutil
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.
aha, i have never seen that pattern before, i think pytest catches the error and then goes back and calls next()
for all the fixtures, so any error that would happen in the test wouldn't stop the cleanup, but i think even if it did this would still be fine so np lemme try that out
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.
there it is :) 86b8c66
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.
I have always used that pattern when testing with databases and rolling back transactions. I would really be interested to know if it's unnecessary.
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.
i think if there was some unhandled exception within pytest itself that caused it to lose the reference to the called fixture object, but didn't completely crash the interpreter, that it would save you there? idk give it a shot, i think there's no reason not to do it, since the next thing after the yield is the finally anyway
i think it ends up being a lot of space because when developing locally you run the tests a bunch of times as you make changes to the package, so the hashes (i'm assuming) of the pyproject keep changing, so i had like 30 envs for the package |
02229e0
to
83405ce
Compare
Co-authored-by: Moritz E. Beber <midnighter@posteo.net>
86b8c66
to
b25f28c
Compare
I was wondering why i was running out of space on my laptop, turns out that the tests were creating a ton of hatch environments that were taking up 9GB, and it seemed like every run was creating new environments.
So this PR just temporarily sets the
HATCH_DATA_DIR
to a tmpdir and cleans it up after the test run. pytest removes temporary directories itself, but it keeps them around for a bit, and since they are big i just manually removed them.I added a
--reuse-envs
flag like nox in case someone wanted to keep those around for some reason. Note that these are not the envs created to run the tests in, but the envs that are created when running the tests for the generated packages.