You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
paths.set_temp_cache and paths.set_temp_config don't reset value if exception occurs in creation #9704
The context managers paths.set_temp_cache and paths.set_temp_config are supposed to let users temporarily reset the locations of the astropy cache and config file. These are used in the test suite but are also user-visible. Unfortunately, as context managers, if an exception occurs in their __enter__ methods, their __exit__ methods are never called; these exit methods are what is supposed to reset the values to their original state, so if an exception is produced, say because something is badly wrong with the requested cache setup, the bogus cache setup is left behind.
This appears as bug #9634 and PR #9703 revealed and should fix the problem; there should be an example in the code for it.
deftest_set_temp_cache_resets_on_exception(tmpdir):
"""Test for regression of bug #9704"""t=paths.get_cache_dir()
a=tmpdir/'a'withopen(a, 'wt') asf:
f.write("not a good cache\n")
withpytest.raises(OSError):
withpaths.set_temp_cache(a):
passassertt==paths.get_cache_dir()
Activity
Reveal bug astropy#9704
Fix astropy#9704
aarchiba commentedon Nov 29, 2019
https://github.com/astropy/astropy/pull/9703/files#diff-a084bf6259662e3a035cd3aeca0323fbR1373 is where the problem is detected - the download dir is not returned to its original value.
aarchiba commentedon Nov 29, 2019
https://github.com/astropy/astropy/pull/9703/files#diff-6e8757768603143a75fb8363ec462764R77 is a better example/regression test:
aarchiba commentedon Nov 30, 2019
Closed by #9703
Re-enable cache warnings, reveal and fix bug astropy#9704
Re-enable cache warnings, reveal and fix bug astropy#9704