Skip to content

BUG: 20 test failures when unsetting the HOME env var #19648

Closed

Description

@neutrinoceros

#19636 was my starting point, but I'm starting to see a problem that's actually a bug and a regression as compared to the 7.2.x branch, so I'm opening this to separate concerns.

There are currently 4 tests failing (some of which are not brand new) on main if pytest is run with HOME= pytest <...>, and the number goes up to 20 with the following patch, which prevent a fixture to mock $HOME if not already defined.

diff --git a/astropy/conftest.py b/astropy/conftest.py
index fd8267156a..cda809e3f9 100644
--- a/astropy/conftest.py
+++ b/astropy/conftest.py
@@ -83,15 +83,15 @@ def ignore_config_paths_global_state(monkeypatch, tmp_path_factory):
             "config",
             pristine_config_finder,
         )
+        if os.getenv("HOME") is not None:
+            # also mock $HOME as it's part of the global state taken into account
+            # for path detection
+            mock_home_dir = tmp_path_factory.mktemp("MOCK_HOME")
 
-        # also mock $HOME as it's part of the global state taken into account
-        # for path detection
-        mock_home_dir = tmp_path_factory.mktemp("MOCK_HOME")
+            def mock_home():
+                return mock_home_dir
 
-        def mock_home():
-            return mock_home_dir
-
-        monkeypatch.setattr(Path, "home", mock_home)
+            monkeypatch.setattr(Path, "home", mock_home)
 
         yield

In contrast, I see no failure on 7.2.x, so this is almost certainly a regression (and definitely an oversight) from #19575
I don't think this is blocking for a beta, but it will be blocking for a rc. I don't think it'll be too difficult to fix, though I do need to take a minute to think it through. In particular, I was surprised to discover that pathlib.Path.home() usually returns the expected path even if HOME isn't set, which might be the origin of some inconsistency in my logic.

I'm assigning myself since it's so clearly up my alley, but this by no means imply that help is unwanted, if anyone wants to participate to the resolution.

Activity

  1. added this to the v8.0.0 milestone on May 3, 2026
  2. self-assigned this
    on May 3, 2026
  3. added
    Affects-devPRs and issues that do not impact an existing Astropy release
    on May 3, 2026
  4. added theissue type on May 3, 2026
  5. changed the title [-]BUG: 20 test failures when unsetting the HOME env var.[/-] [+]BUG: 20 test failures when unsetting the HOME env var[/+] on May 4, 2026
  6. pllim commented on May 5, 2026

    @pllim
    Member

    In what real world situation would someone unset HOME?

  7. neutrinoceros commented on May 5, 2026

    @neutrinoceros
    ContributorAuthor

    The actual use case is that some systems might not define it at all. In any case this was explicitly supported (even though untested) in previous version so I don't want to introduce a subtly broken revision without careful inquiry.

  8. neutrinoceros commented on May 8, 2026

    @neutrinoceros
    ContributorAuthor

    Update: 0 tests failing on main without the patch above, and only one with it: test_env_variables_missing_subdir_and_default (depending on the presence of a file). This one test should monkeypatch Path.home itself.

  9. pllim commented on May 8, 2026

    @pllim
    Member

    Looking at #19712 , you have decided that this is only a testing problem after all, not a production bug?

  10. neutrinoceros commented on May 8, 2026

    @neutrinoceros
    ContributorAuthor

    not really, it's just that every other failure point already went away as I fixed other aspects of the new system. #19712 fixes the only remaining problems.

  11. pllim commented on May 8, 2026

    @pllim
    Member

    For future reference, exactly with other PR fixed the actual bug reported here?

  12. neutrinoceros commented on May 8, 2026

    @neutrinoceros
    ContributorAuthor

    I don't know for sure, this was an unexpected result, and looking back at the recent merger doesn't yield any obvious answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Affects-devPRs and issues that do not impact an existing Astropy releaseBugconfig

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions