-
Notifications
You must be signed in to change notification settings - Fork 92
Clean up files written to tmpdir during tests #2505
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2505 +/- ##
=======================================
+ Coverage 99.7% 99.7% +0.1%
=======================================
Files 283 283
Lines 25585 25589 +4
=======================================
+ Hits 25483 25488 +5
+ Misses 102 101 -1
Continue to review full report at Codecov.
|
evalml/tests/conftest.py
Outdated
|
|
||
|
|
||
| @pytest.fixture | ||
| def tmpdir_with_cleanup(tmpdir): |
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 are other ways to clean up files after a test that don't involve using a new fixture (see here) but this seems simpler to me
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.
why not just use one fixture instead of having one for the tmpdir and one for cleaning up? Are there some tests we don't want the clean up functionality?
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.
Great suggestion. I don't think we ever want to not clean up after the test. I thought about this but tbh
@pytest.fixture
def tmpdir(tmpdir):
yield tmpdir
tmpdir.remove(ignore_errors=True)looked weird to me. That being said, I will try the following:
@pytest.fixture
def tmpdir(tmp_path):
dir = py.path.local(tmp_path)
yield dir
dir.remove(ignore_errors=True)which I think will work and will involve less code changes!
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.
Pushed this up! Thanks for the suggestion - it's working nicely
| - main | ||
| pull_request: | ||
| types: [ opened, synchronize ] | ||
| paths: |
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.
Will add back before merge
evalml/tests/conftest.py
Outdated
| @pytest.fixture | ||
| def tmpdir_with_cleanup(tmpdir): | ||
| yield tmpdir | ||
| tmpdir.remove(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.
I tested locally that this removes the directory even if the test fails.
jeremyliweishih
left a comment
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.
looks good! just one question.
evalml/tests/conftest.py
Outdated
|
|
||
|
|
||
| @pytest.fixture | ||
| def tmpdir_with_cleanup(tmpdir): |
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.
why not just use one fixture instead of having one for the tmpdir and one for cleaning up? Are there some tests we don't want the clean up functionality?
angela97lin
left a comment
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'm surprised that this isn't something built into tmpdir :( but looks good, thank you!
Pull Request Description
Fixes #2337
build_conda_pkghas passed three times already. It used to fail consistently whentest_save_png_filewas enabled. I ran locally with--basetemp mydirformainand--basetemp mydir-new-fixturefor this branch. The total space on this branch is 0 bytes compared to 22 mb on main.After creating the pull request: in order to pass the release_notes_updated check you will need to update the "Future Release" section of
docs/source/release_notes.rstto include this pull request by adding :pr:123.