Clean up configuration write lock files in the test suite
Marco Ricci

Marco Ricci commited on 2025-04-09 19:27:50
Zeige 1 geänderte Dateien mit 11 Einfügungen und 1 Löschungen.


When using a temporary, isolated `derivepassphrase` configuration
directory in the test suite, also clean up the matching configuration
write lock file, which is not located in the configuration directory.
... ...
@@ -1725,7 +1725,7 @@ def isolated_config(
1725 1725
         A context manager, without a return value.
1726 1726
 
1727 1727
     """
1728
-    prog_name = cli.PROG_NAME
1728
+    prog_name = cli_helpers.PROG_NAME
1729 1729
     env_name = prog_name.replace(' ', '_').upper() + '_PATH'
1730 1730
     # TODO(the-13th-letter): Rewrite using parenthesized with-statements.
1731 1731
     # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
... ...
@@ -1747,7 +1747,10 @@ def isolated_config(
1747 1747
             cli_helpers.config_filename('user configuration').write_text(
1748 1748
                 main_config_str, encoding='UTF-8'
1749 1749
             )
1750
+        try:
1750 1751
             yield
1752
+        finally:
1753
+            cli_helpers.config_filename('write lock').unlink(missing_ok=True)
1751 1754
 
1752 1755
 
1753 1756
 @contextlib.contextmanager
... ...
@@ -1846,6 +1849,10 @@ def isolated_vault_exporter_config(
1846 1849
         cwd = str(pathlib.Path.cwd().resolve())
1847 1850
         monkeypatch.setenv('HOME', cwd)
1848 1851
         monkeypatch.setenv('USERPROFILE', cwd)
1852
+        monkeypatch.delenv(
1853
+            cli_helpers.PROG_NAME.replace(' ', '_').upper() + '_PATH',
1854
+            raising=False,
1855
+        )
1849 1856
         monkeypatch.delenv('VAULT_PATH', raising=False)
1850 1857
         monkeypatch.delenv('VAULT_KEY', raising=False)
1851 1858
         monkeypatch.delenv('LOGNAME', raising=False)
... ...
@@ -1878,7 +1885,10 @@ def isolated_vault_exporter_config(
1878 1885
             pass
1879 1886
         else:  # pragma: no cover
1880 1887
             assert_never(vault_config)
1888
+        try:
1881 1889
             yield
1890
+        finally:
1891
+            cli_helpers.config_filename('write lock').unlink(missing_ok=True)
1882 1892
 
1883 1893
 
1884 1894
 def auto_prompt(*args: Any, **kwargs: Any) -> str:
1885 1895