Skip to content

Commit

Permalink
Fix ConfigTest failures locally
Browse files Browse the repository at this point in the history
A couple of `ConfigTest` would previously fail locally since they
somehow depended on the local environment to work fine. This commmit
decouples them from any environment by setting up patching of the
environment variables properly.
  • Loading branch information
snejus committed Jul 13, 2024
1 parent e9e2e02 commit 604a683
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions test/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,9 @@ def setUp(self):
# Don't use the BEETSDIR from `helper`. Instead, we point the home
# directory there. Some tests will set `BEETSDIR` themselves.
del os.environ["BEETSDIR"]
self._old_home = os.environ.get("HOME")
os.environ["HOME"] = os.fsdecode(self.temp_dir)

# Also set APPDATA, the Windows equivalent of setting $HOME.
self._old_appdata = os.environ.get("APPDATA")
os.environ["APPDATA"] = os.fsdecode(
appdata_dir = os.fsdecode(
os.path.join(self.temp_dir, b"AppData", b"Roaming")
)

Expand All @@ -846,9 +843,7 @@ def setUp(self):

# Default user configuration
if platform.system() == "Windows":
self.user_config_dir = os.path.join(
self.temp_dir, b"AppData", b"Roaming", b"beets"
)
self.user_config_dir = os.path.join(appdata_dir, b"beets")
else:
self.user_config_dir = os.path.join(
self.temp_dir, b".config", b"beets"
Expand All @@ -861,19 +856,19 @@ def setUp(self):
# Custom BEETSDIR
self.beetsdir = os.path.join(self.temp_dir, b"beetsdir")
os.makedirs(syspath(self.beetsdir))
self.env_patcher = patch(
"os.environ",
{"HOME": os.fsdecode(self.temp_dir), "APPDATA": appdata_dir},
)
self.env_patcher.start()

self._reset_config()
self.load_plugins()

def tearDown(self):
self.env_patcher.stop()
commands.default_commands.pop()
os.chdir(syspath(self._orig_cwd))
if self._old_home is not None:
os.environ["HOME"] = self._old_home
if self._old_appdata is None:
del os.environ["APPDATA"]
else:
os.environ["APPDATA"] = self._old_appdata
self.unload_plugins()
super().tearDown()

Expand Down

0 comments on commit 604a683

Please sign in to comment.