-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
file testing issue - tmp file cleanup #5285
base: master
Are you sure you want to change the base?
Conversation
Added cleanup function to address the creation of unnecessary tmp files during testing
Add cleanup function to test files to remove temporary files
Add cleanup function to test files to remove temporary files
Add cleanup function to test files to remove temporary files
Add cleanup function to test files to remove temporary files
Add cleanup function to test files to remove temporary files
Hi @khrystianc , thanks for this! I did a quick test using the same shell command as I mentioned in the issue for fi in test/plugins/*.py; do
print Testing $fi && pytest $fi --no-cov &>/dev/null
drs=(/tmp/tmp*)
if (( $#drs )); then
print -l $drs && rm -r $drs
fi
done
it seems like the situation stays the same? |
|
||
if __name__ == "__main__": | ||
unittest.main(defaultTest="suite") | ||
|
||
# Cleanup temporary files |
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 see that this cleanup only runs when this script is called directly
if __name__ == "__main__":
Since we use pytest
to run tests, I think this logic may not run. Have you tried running, say, pytest test/plugins/test_art.py
and checking whether the files have been removed?
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.
Thank you for the quick response. Let me review and get back to you.
@khrystianc from what I've seen most of the offending tests use inherit from the def setup_beets(self, disk=False):
"""Setup pristine global configuration and library for testing.
Sets ``beets.config`` so we can safely use any functionality
that uses the global configuration. All paths used are
contained in a temporary directory
Sets the following properties on itself.
- ``temp_dir`` Path to a temporary directory containing all
files specific to beets
- ``libdir`` Path to a subfolder of ``temp_dir``, containing the
library's media files. Same as ``config['directory']``.
- ``config`` The global configuration used by beets.
- ``lib`` Library instance created with the settings from
``config``.
Make sure you call ``teardown_beets()`` afterwards.
"""
self.create_temp_dir()
os.environ["BEETSDIR"] = util.py3_path(self.temp_dir)
self.config = beets.config
self.config.clear()
self.config.read()
self.config["plugins"] = []
self.config["verbose"] = 1
self.config["ui"]["color"] = False
self.config["threaded"] = False
self.libdir = os.path.join(self.temp_dir, b"libdir")
os.mkdir(syspath(self.libdir))
self.config["directory"] = util.py3_path(self.libdir)
if disk:
dbpath = util.bytestring_path(self.config["library"].as_filename())
else:
dbpath = ":memory:"
self.lib = Library(dbpath, self.libdir) Note the last sentence in the docstring with the following warning:
I have a feeling that these tests may be misusing this functionality, where |
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 really worried about this implementation. If the user has other files named /tmp/tmp*
, which is entirely possible, they will get wiped out completely by this. We need a much more sophisticated solution to solve this -- or we should use /tmp/beets-test/*
for all our temporary files. Less importantly, the cleanup_tmp_files()
function has been duplicated to a bunch of test modules -- why not define it once and import it everywhere else?
@bal-e I agree. I see what you mean. If you've got an idea on how to implement this, please give it a shot. If not, I will continue to work this issue and definitely take this observation to into account. Thank you so much |
Description
Fixes #5229
(#5229)
To Do
docs/
to describe it.)docs/changelog.rst
to the bottom of one of the lists near the top of the document.)