beets/beetsplug
Šarūnas Nejus 1163645604
Make sure tests do not leave any temp files behind (#5345)
Fixes #5229, is part of #5361 and relates to #5285.

I have to admit thsi was a fairly tough task - I initially assumed that
the problem lies
with how the tests are setup, and that we're probably missing some
`teardown_beets` calls
here and there.

Unfortunately, it was not so simple. I came across several issues that
gave rise to
leftover temporary files:

1. `fetchart`, `artresizer` and `play` handling of temporary files.
These plugins created
isolated temporary files outside of the directories that tests clean up.
You will find
I added a couple of functions (namely `get_module_tempdir`) that force
these plugins to
create files in directories determined by their module names. This way
we can clean up
   after them using the new `CleanupModulesMixin`.

2. Tests that ran temporary directories setup twice, running
`_common.TestCase.setUp` and
`test.helper.TestHelper.setup_beets`. Both of these ran `self.temp_dir =
mkdtemp()`,
therefore the directories created by the initial setup persisted since
those have been
overridden and thus unreachable in the teardown. Here, I removed the
`setUp` calls, see

   - `test/plugins/test_embedart.py`
   - `test/test_importer.py`
   - and `test/test_plugins.py` where `setup_beets` was called twice

3. `test/test_config_command.py` attempted to manage the temporary
directory by itself,
where I found that `tearDown` failed to remove the directory for four
tests. Could not
figure out the cause, and found that delegating this task to
`TestHelper` fixed the
   issue.

4. Mediafile fixture removal depended on calling
`remove_mediafile_fixtures` method, which
`test/plugins/test_zero.py` failed to do. I made the fixtures to be
created within the
same `temp_dir` directory that gets removed in the teardown, so now they
are taken care
   of automatically.

In summary, see the test modules that left files behind:

```
Temp files created by test/__init__.py
Temp files created by test/plugins/__init__.py
Temp files created by test/plugins/lyrics_download_samples.py
Temp files created by test/plugins/test_acousticbrainz.py
Temp files created by test/plugins/test_advancedrewrite.py
Temp files created by test/plugins/test_albumtypes.py
Temp files created by test/plugins/test_art.py
	/tmp/tmp11nicahe.jpg
	/tmp/tmp1bjmodum.png
	/tmp/tmped7nhls4.jpg
	/tmp/tmpflnzr9wz.jpg
	/tmp/tmpjngkauqs.png
	/tmp/tmpkzy9mn6t.jpg
	/tmp/tmpph_wmuea.jpg
	/tmp/tmps6gk58i_.jpg
	/tmp/tmpz2eji_o4.jpg
Temp files created by test/plugins/test_aura.py
Temp files created by test/plugins/test_bareasc.py
	/tmp/tmphl3kzhug
	/tmp/tmpnh2q6v02
	/tmp/tmpppw5qrhz
Temp files created by test/plugins/test_beatport.py
Temp files created by test/plugins/test_bucket.py
Temp files created by test/plugins/test_convert.py
Temp files created by test/plugins/test_discogs.py
Temp files created by test/plugins/test_edit.py
Temp files created by test/plugins/test_embedart.py
	/tmp/tmp1ayvqzhx
	/tmp/tmp58k6mdfx.jpg
	/tmp/tmp64c2lqiv
	/tmp/tmp6nar4kr5
	/tmp/tmp6u0d5dex
	/tmp/tmpacoq7w_f
	/tmp/tmpajnr_sxr
	/tmp/tmpasj16beh
	/tmp/tmpboyaixb5
	/tmp/tmpcrmcyt5r
	/tmp/tmpdomje5g3
	/tmp/tmplu3o6t6g
	/tmp/tmpns_xvkns
	/tmp/tmpo87o1h6o.jpg
	/tmp/tmpqem39h_j
	/tmp/tmprlzm18pb
	/tmp/tmpt22v4u6x
	/tmp/tmptp3rxdgv
Temp files created by test/plugins/test_embyupdate.py
Temp files created by test/plugins/test_export.py
Temp files created by test/plugins/test_fetchart.py
Temp files created by test/plugins/test_filefilter.py
Temp files created by test/plugins/test_ftintitle.py
Temp files created by test/plugins/test_hook.py
Temp files created by test/plugins/test_ihate.py
Temp files created by test/plugins/test_importadded.py
Temp files created by test/plugins/test_importfeeds.py
Temp files created by test/plugins/test_info.py
Temp files created by test/plugins/test_ipfs.py
Temp files created by test/plugins/test_keyfinder.py
Temp files created by test/plugins/test_lastgenre.py
Temp files created by test/plugins/test_limit.py
Temp files created by test/plugins/test_lyrics.py
Temp files created by test/plugins/test_mbsubmit.py
Temp files created by test/plugins/test_mbsync.py
Temp files created by test/plugins/test_mpdstats.py
Temp files created by test/plugins/test_parentwork.py
Temp files created by test/plugins/test_permissions.py
Temp files created by test/plugins/test_player.py
Temp files created by test/plugins/test_playlist.py
Temp files created by test/plugins/test_play.py
	/tmp/tmp6ohknmve.m3u
	/tmp/tmp8rw2z_j4.m3u
	/tmp/tmp9vi27ypx.m3u
	/tmp/tmpa_s66jh8.m3u
	/tmp/tmpb7h3cn3n.m3u
	/tmp/tmpexbmqvry.m3u
	/tmp/tmpinbqrt80.m3u
	/tmp/tmpql02hax5.m3u
	/tmp/tmpvbdzprsf.m3u
	/tmp/tmpzipim36x.m3u
Temp files created by test/plugins/test_plexupdate.py
Temp files created by test/plugins/test_plugin_mediafield.py
Temp files created by test/plugins/test_random.py
Temp files created by test/plugins/test_replaygain.py
Temp files created by test/plugins/test_smartplaylist.py
Temp files created by test/plugins/test_spotify.py
Temp files created by test/plugins/test_subsonicupdate.py
Temp files created by test/plugins/test_the.py
Temp files created by test/plugins/test_thumbnails.py
Temp files created by test/plugins/test_types_plugin.py
Temp files created by test/plugins/test_web.py
Temp files created by test/plugins/test_zero.py
	/tmp/tmp3ub9xmzy
Temp files created by test/rsrc/beetsplug/test.py
Temp files created by test/rsrc/convert_stub.py
Temp files created by test/testall.py
Temp files created by test/test_art_resize.py
	/tmp/tmp3p7p60ih.jpg
	/tmp/tmp8exclgit.jpg
	/tmp/tmpkrrjsitl.jpg
	/tmp/tmpw6n8ee8e.jpg
	/tmp/tmpygws_0aw.jpg
Temp files created by test/test_autotag.py
Temp files created by test/test_config_command.py
	/tmp/tmp333f0r2j
	/tmp/tmphr356z5r
	/tmp/tmporp4rag2
	/tmp/tmpy7sjqdsw
Temp files created by test/test_datequery.py
Temp files created by test/test_dbcore.py
Temp files created by test/test_files.py
Temp files created by test/test_hidden.py
Temp files created by test/test_importer.py
	/tmp/tmp0m363gfb
	/tmp/tmp2n3i13mc
	/tmp/tmpxk3v304s
Temp files created by test/test_library.py
Temp files created by test/test_logging.py
Temp files created by test/test_m3ufile.py
Temp files created by test/test_mb.py
Temp files created by test/test_metasync.py
Temp files created by test/test_pipeline.py
Temp files created by test/test_plugins.py
	/tmp/tmp6pxhx67u
	/tmp/tmpb8pqi9ui
	/tmp/tmpcx_658g7
	/tmp/tmp_giqb9jz
	/tmp/tmpgm9xk94_
	/tmp/tmpk60l6bt3
	/tmp/tmpqoj4la68
	/tmp/tmptcdu20rp
	/tmp/tmpvr7k5shn
	/tmp/tmpwnfnzs91
Temp files created by test/test_query.py
Temp files created by test/test_sort.py
Temp files created by test/test_template.py
Temp files created by test/test_ui_commands.py
	/tmp/tmpns2u94w6
Temp files created by test/test_ui_importer.py
Temp files created by test/test_ui_init.py
Temp files created by test/test_ui.py
Temp files created by test/test_util.py
Temp files created by test/test_vfs.py
```

And that's what we have right now:

```
Temp files created by test/__init__.py
Temp files created by test/plugins/__init__.py
Temp files created by test/plugins/lyrics_download_samples.py
Temp files created by test/plugins/test_acousticbrainz.py
Temp files created by test/plugins/test_advancedrewrite.py
Temp files created by test/plugins/test_albumtypes.py
Temp files created by test/plugins/test_art.py
Temp files created by test/plugins/test_aura.py
Temp files created by test/plugins/test_bareasc.py
Temp files created by test/plugins/test_beatport.py
Temp files created by test/plugins/test_bucket.py
Temp files created by test/plugins/test_convert.py
Temp files created by test/plugins/test_discogs.py
Temp files created by test/plugins/test_edit.py
Temp files created by test/plugins/test_embedart.py
Temp files created by test/plugins/test_embyupdate.py
Temp files created by test/plugins/test_export.py
Temp files created by test/plugins/test_fetchart.py
Temp files created by test/plugins/test_filefilter.py
Temp files created by test/plugins/test_ftintitle.py
Temp files created by test/plugins/test_hook.py
Temp files created by test/plugins/test_ihate.py
Temp files created by test/plugins/test_importadded.py
Temp files created by test/plugins/test_importfeeds.py
Temp files created by test/plugins/test_info.py
Temp files created by test/plugins/test_ipfs.py
Temp files created by test/plugins/test_keyfinder.py
Temp files created by test/plugins/test_lastgenre.py
Temp files created by test/plugins/test_limit.py
Temp files created by test/plugins/test_lyrics.py
Temp files created by test/plugins/test_mbsubmit.py
Temp files created by test/plugins/test_mbsync.py
Temp files created by test/plugins/test_mpdstats.py
Temp files created by test/plugins/test_parentwork.py
Temp files created by test/plugins/test_permissions.py
Temp files created by test/plugins/test_player.py
Temp files created by test/plugins/test_playlist.py
Temp files created by test/plugins/test_play.py
Temp files created by test/plugins/test_plexupdate.py
Temp files created by test/plugins/test_plugin_mediafield.py
Temp files created by test/plugins/test_random.py
Temp files created by test/plugins/test_replaygain.py
Temp files created by test/plugins/test_smartplaylist.py
Temp files created by test/plugins/test_spotify.py
Temp files created by test/plugins/test_subsonicupdate.py
Temp files created by test/plugins/test_the.py
Temp files created by test/plugins/test_thumbnails.py
Temp files created by test/plugins/test_types_plugin.py
Temp files created by test/plugins/test_web.py
Temp files created by test/plugins/test_zero.py
Temp files created by test/rsrc/beetsplug/test.py
Temp files created by test/rsrc/convert_stub.py
Temp files created by test/testall.py
Temp files created by test/test_art_resize.py
Temp files created by test/test_autotag.py
Temp files created by test/test_config_command.py
Temp files created by test/test_datequery.py
Temp files created by test/test_dbcore.py
Temp files created by test/test_files.py
Temp files created by test/test_hidden.py
Temp files created by test/test_importer.py
Temp files created by test/test_library.py
Temp files created by test/test_logging.py
Temp files created by test/test_m3ufile.py
Temp files created by test/test_mb.py
Temp files created by test/test_metasync.py
Temp files created by test/test_pipeline.py
Temp files created by test/test_plugins.py
Temp files created by test/test_query.py
Temp files created by test/test_sort.py
Temp files created by test/test_template.py
Temp files created by test/test_ui_commands.py
Temp files created by test/test_ui_importer.py
Temp files created by test/test_ui_init.py
Temp files created by test/test_ui.py
Temp files created by test/test_util.py
Temp files created by test/test_vfs.py
```

Note that the command which provides the output is now available through
`poe`.
2024-07-18 12:25:23 +01:00
..
bpd Revert "Make queries fast, filter all flexible attributes (#5240)" 2024-06-19 21:51:44 +01:00
lastgenre Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
metasync Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
web Replace py3_path with builtin os.fsdecode 2024-06-16 00:52:37 +01:00
__init__.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
absubmit.py Add timeout to all requests calls 2024-05-25 12:24:53 -03:00
acousticbrainz.py Codestyle 2024-05-26 11:57:24 -03:00
advancedrewrite.py Merge pull request #5063 from Maxr1998/fix-advancedrewrite-simple-rules 2024-03-01 16:08:37 +10:00
albumtypes.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
aura.py Check Python version instead of catching ImportError 2024-06-22 19:55:52 +03:00
autobpm.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
badfiles.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
bareasc.py Keep the same FieldQuery.field interface as before 2024-06-17 08:59:20 +01:00
beatport.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
bench.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
bpm.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
bpsync.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
bucket.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
chroma.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
convert.py Use native os.cpu_count 2024-06-16 00:52:38 +01:00
deezer.py Add timeout to all requests calls 2024-05-25 12:24:53 -03:00
discogs.py A couple of small updates in the code 2024-06-05 04:41:02 +01:00
duplicates.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
edit.py Use gender-neutral language 2023-10-23 17:41:38 -04:00
embedart.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
embyupdate.py Codestyle 2024-05-26 11:57:24 -03:00
export.py Apply formatting 2024-03-01 15:21:25 +10:00
fetchart.py fetchart, artresizer: Create art files in predictable directories 2024-07-02 15:35:24 +01:00
filefilter.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
fish.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
freedesktop.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
fromfilename.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
ftintitle.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
fuzzy.py Resolve some 'mypy' errors 2024-06-12 15:58:00 +02:00
gmusic.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
hook.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
ihate.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
importadded.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
importfeeds.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
info.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
inline.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
ipfs.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
keyfinder.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
kodiupdate.py Add timeout to all requests calls 2024-05-25 12:24:53 -03:00
lastimport.py Update lastimport.py 2023-12-20 10:28:45 -05:00
limit.py Add support for filtering relations 2024-06-21 15:05:29 +01:00
listenbrainz.py Add logging 2023-12-23 12:19:04 -05:00
loadext.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
lyrics.py Filter ending newlines 2024-07-11 15:15:40 +10:00
mbcollection.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
mbsubmit.py mbsubmit: Add picard PromptChoice 2023-12-05 13:49:03 +02:00
mbsync.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
missing.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
mpdstats.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
mpdupdate.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
parentwork.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
permissions.py Apply formatting 2024-03-01 15:21:25 +10:00
play.py test_play: Remove files generated by play plugin 2024-07-02 15:35:24 +01:00
playlist.py Add support for a specific type in InQuery 2024-04-30 22:20:36 +01:00
plexupdate.py Add timeout to all requests calls 2024-05-25 12:24:53 -03:00
random.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
replaygain.py Use native os.cpu_count 2024-06-16 00:52:38 +01:00
rewrite.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
scrub.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
smartplaylist.py smartplaylist: rename output format m3u8 to extm3u 2024-04-13 04:55:43 +02:00
sonosupdate.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
spotify.py Add timeout to all requests calls 2024-05-25 12:24:53 -03:00
subsonicplaylist.py Add timeout to all requests calls 2024-05-25 12:24:53 -03:00
subsonicupdate.py Add timeout to all requests calls 2024-05-25 12:24:53 -03:00
substitute.py A couple of small updates in the code 2024-06-05 04:41:02 +01:00
the.py Resolve some 'mypy' errors 2024-06-12 15:58:00 +02:00
thumbnails.py Replace py3_path with builtin os.fsdecode 2024-06-16 00:52:37 +01:00
types.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00
unimported.py bugfix: ignore subdirectories of ignored 2024-03-22 18:20:47 -04:00
zero.py Apply formatting tools to all files 2023-10-22 09:53:18 +10:00