Change setting up temporary directories in astropy test runner#17529
Change setting up temporary directories in astropy test runner#17529neutrinoceros merged 1 commit intoastropy:mainfrom
astropy test runner#17529Conversation
Testing the effect of the `XDG_CACHE_HOME` and `XDG_CONFIG_HOME` environment variables using the `astropy` test runner (like the double test CI job does) did not work because the test runner used `set_temp_cache` and `set_temp_config` context managers, which have priority over the environment variables. The test runner has no need to configure the cache directory because `pytest` is configured to do that anyways. Setting up a temporary configuration directory is required to guarantee that `pytest` uses the temporary `astropy` configuration before its own configuration is read, but `set_temp_cache` should nonetheless be avoided.
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
neutrinoceros
left a comment
There was a problem hiding this comment.
LGTM. Thanks a lot for the comprehensive writeup ! even being involved in previous discussions it was very helpful for me to get back into this specific context.
| return pytest.main(args=args, plugins=plugins) | ||
| finally: | ||
| if orig_xdg_config is None: | ||
| os.environ.pop("XDG_CONFIG_HOME", None) |
There was a problem hiding this comment.
I did a double take on the second argument. I now agree this is the correct thing to do: even if this environment variable is supposed to be defined at this point, we cannot guarantee it is still there, and we certainly do no want to raise an exception within a finally clause.
… `astropy` test runner
…529-on-v7.0.x Backport PR #17529 on branch v7.0.x (Change setting up temporary directories in `astropy` test runner)
|
Thanks! But seems like I didn't get to this soon enough.
Where is that done; can you please link? I think the original reason was to ensure the second run does not accidentally read in cached stuff from first run, but @astrofrog can correct me if I am wrong. |
|
Lines 69 to 76 in abc83b4 Lines 87 to 99 in abc83b4 Lines 14 to 21 in abc83b4 And if the It is simple to prevent our test runner from creating a configuration directory by invoking From what I can tell having |
|
Ah, right... Is there a way to check if |
Yes: so yes, it's in there (I checked that it is indeed identical to |
Description
astropyv7.0.0 has a bug that causes theXDG_CACHE_HOMEenvironment variable to have no effect. InsteadXDG_CONFIG_HOMEcontrols both the cache and configuration directories. #17514 would restore the correct pre-v7.0.0 behavior, but it failed the double test CI job. That job uses theastropytest runner instead of callingpytestdirectly, and our test runner sets up temporary directories with theset_temp_cacheandset_temp_configcontext managers, which have priority over the environment variables. The failure in #17514 is therefore specific to our test runner and it is not revealing any mistakes in the regression test or in the relevant code. It would be possible to avoid this problem by complicating the regression test, but that is not a robust solution and it is not needed at all ifpytestis called directly. It is our test runner that should be edited to avoid using the aforementioned context managers. Ourpytestconfiguration already uses the environment variables instead of the context managers, so this change also makes our test runner configuration more similar to that.I don't see any reason why the test runner should set up a temporary cache directory because we configure
pytestto do that anyways (it actually creates more than one). It is also not obvious to me why our runner should set up a temporary configuration directory, but a code comment (by @astrofrog) mentions timing concerns. I chose to trust the comment, so I replaced rather than removedset_temp_config.This pull request must be backported because otherwise backporting #17514 will cause double test CI job failures in the
v7.0.xbranch.