Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion test/plugins/test_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

logger = logging.getLogger("beets.test_art")


Check failure on line 36 in test/plugins/test_art.py

View workflow job for this annotation

GitHub Actions / lint

W293 blank line contains whitespace
class Settings:
"""Used to pass settings to the ArtSources when the plugin isn't fully
instantiated.
Expand Down Expand Up @@ -1019,6 +1019,21 @@
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)

def cleanup_tmp_files():

Check failure on line 1022 in test/plugins/test_art.py

View workflow job for this annotation

GitHub Actions / lint

E302 expected 2 blank lines, found 1
# List all files and directories in /tmp that start with 'tmp'
temp_files = [f for f in os.listdir('/tmp') if f.startswith('tmp')]

Check failure on line 1025 in test/plugins/test_art.py

View workflow job for this annotation

GitHub Actions / lint

W293 blank line contains whitespace
# Remove each file or directory
for f in temp_files:
temp_path = os.path.join('/tmp', f)
if os.path.isdir(temp_path):
shutil.rmtree(temp_path)
else:
os.remove(temp_path)


if __name__ == "__main__":
unittest.main(defaultTest="suite")

Check failure on line 1037 in test/plugins/test_art.py

View workflow job for this annotation

GitHub Actions / lint

W293 blank line contains whitespace
# Cleanup temporary files
Copy link
Member

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?

Copy link
Author

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.

cleanup_tmp_files()
17 changes: 17 additions & 0 deletions test/plugins/test_bareasc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

"""Tests for the 'bareasc' plugin."""

import os
import shutil
import unittest

from beets import logging
Expand Down Expand Up @@ -87,6 +89,21 @@
"""loader."""
return unittest.TestLoader().loadTestsFromName(__name__)

def cleanup_tmp_files():

Check failure on line 92 in test/plugins/test_bareasc.py

View workflow job for this annotation

GitHub Actions / lint

E302 expected 2 blank lines, found 1
# List all files and directories in /tmp that start with 'tmp'
temp_files = [f for f in os.listdir('/tmp') if f.startswith('tmp')]

Check failure on line 95 in test/plugins/test_bareasc.py

View workflow job for this annotation

GitHub Actions / lint

W293 blank line contains whitespace
# Remove each file or directory
for f in temp_files:
temp_path = os.path.join('/tmp', f)
if os.path.isdir(temp_path):
shutil.rmtree(temp_path)
else:
os.remove(temp_path)


if __name__ == "__main__":
unittest.main(defaultTest="suite")

# Cleanup temporary files
cleanup_tmp_files()
16 changes: 16 additions & 0 deletions test/plugins/test_embedart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


import os.path
import os
import shutil
import tempfile
import unittest
Expand Down Expand Up @@ -350,6 +351,21 @@
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)

def cleanup_tmp_files():

Check failure on line 354 in test/plugins/test_embedart.py

View workflow job for this annotation

GitHub Actions / lint

E302 expected 2 blank lines, found 1
# List all files and directories in /tmp that start with 'tmp'
temp_files = [f for f in os.listdir('/tmp') if f.startswith('tmp')]

Check failure on line 357 in test/plugins/test_embedart.py

View workflow job for this annotation

GitHub Actions / lint

W293 blank line contains whitespace
# Remove each file or directory
for f in temp_files:
temp_path = os.path.join('/tmp', f)
if os.path.isdir(temp_path):
shutil.rmtree(temp_path)
else:
os.remove(temp_path)

Check failure on line 365 in test/plugins/test_embedart.py

View workflow job for this annotation

GitHub Actions / lint

W293 blank line contains whitespace

if __name__ == "__main__":
unittest.main(defaultTest="suite")

# Cleanup temporary files
cleanup_tmp_files()
17 changes: 17 additions & 0 deletions test/plugins/test_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


import os
import shutil
import sys
import unittest
from unittest.mock import ANY, patch
Expand Down Expand Up @@ -147,6 +148,22 @@
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)

def cleanup_tmp_files():

Check failure on line 151 in test/plugins/test_play.py

View workflow job for this annotation

GitHub Actions / lint

E302 expected 2 blank lines, found 1
# List all files and directories in /tmp that start with 'tmp'
temp_files = [f for f in os.listdir('/tmp') if f.startswith('tmp')]

# Remove each file or directory
for f in temp_files:
temp_path = os.path.join('/tmp', f)
if os.path.isdir(temp_path):
shutil.rmtree(temp_path)
else:
os.remove(temp_path)


if __name__ == "__main__":
unittest.main(defaultTest="suite")

# Cleanup temporary files
cleanup_tmp_files()

18 changes: 18 additions & 0 deletions test/plugins/test_zero.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for the 'zero' plugin"""

import os
import shutil
import unittest

from mediafile import MediaFile
Expand Down Expand Up @@ -297,6 +299,22 @@ def test_empty_query_n_response_no_changes(self):
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)

def cleanup_tmp_files():
# List all files and directories in /tmp that start with 'tmp'
temp_files = [f for f in os.listdir('/tmp') if f.startswith('tmp')]

# Remove each file or directory
for f in temp_files:
temp_path = os.path.join('/tmp', f)
if os.path.isdir(temp_path):
shutil.rmtree(temp_path)
else:
os.remove(temp_path)


if __name__ == "__main__":
unittest.main(defaultTest="suite")

# Cleanup temporary files
cleanup_tmp_files()

Loading