Repository: borgbackup/borg

Issue:
many files in ~/.config/borg/key-nonces dir
I just deleted 14.500 files from there. I suspect they were generated from borg unit tests...



Discussion:
Confirmed. Looks very much like unit tests. Should bend BORG_NONCES_DIR in tests to the appropriate tempdir where the repo lives, too.

testsuite.key has a fixture to stop leaving files around. But that one was not copied to the noncemanager  test.

```
@pytest.fixture(autouse=True)
def nonce_dir(tmpdir_factory, monkeypatch):
    monkeypatch.setenv('XDG_CONFIG_HOME', tmpdir_factory.mktemp('xdg-config-home'))
```

But maybe we want to do this more global. 


Resolving patch:
diff --git a/src/borg/testsuite/benchmark.py b/src/borg/testsuite/benchmark.py
--- a/src/borg/testsuite/benchmark.py
+++ b/src/borg/testsuite/benchmark.py
@@ -14,13 +14,13 @@
 
 
 @pytest.yield_fixture
-def repo_url(request, tmpdir):
-    os.environ['BORG_PASSPHRASE'] = '123456'
-    os.environ['BORG_CHECK_I_KNOW_WHAT_I_AM_DOING'] = 'YES'
-    os.environ['BORG_DELETE_I_KNOW_WHAT_I_AM_DOING'] = 'YES'
-    os.environ['BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK'] = 'yes'
-    os.environ['BORG_KEYS_DIR'] = str(tmpdir.join('keys'))
-    os.environ['BORG_CACHE_DIR'] = str(tmpdir.join('cache'))
+def repo_url(request, tmpdir, monkeypatch):
+    monkeypatch.setenv('BORG_PASSPHRASE', '123456')
+    monkeypatch.setenv('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING', 'YES')
+    monkeypatch.setenv('BORG_DELETE_I_KNOW_WHAT_I_AM_DOING', 'YES')
+    monkeypatch.setenv('BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK', 'yes')
+    monkeypatch.setenv('BORG_KEYS_DIR', str(tmpdir.join('keys')))
+    monkeypatch.setenv('BORG_CACHE_DIR', str(tmpdir.join('cache')))
     yield str(tmpdir.join('repository'))
     tmpdir.remove(rec=1)
 
diff --git a/src/borg/testsuite/helpers.py b/src/borg/testsuite/helpers.py
--- a/src/borg/testsuite/helpers.py
+++ b/src/borg/testsuite/helpers.py
@@ -823,21 +823,20 @@ def test_yes_input_custom():
     assert not yes(falsish=('NOPE', ), input=input)
 
 
-def test_yes_env():
+def test_yes_env(monkeypatch):
     for value in TRUISH:
-        with environment_variable(OVERRIDE_THIS=value):
-            assert yes(env_var_override='OVERRIDE_THIS')
+        monkeypatch.setenv('OVERRIDE_THIS', value)
+        assert yes(env_var_override='OVERRIDE_THIS')
     for value in FALSISH:
-        with environment_variable(OVERRIDE_THIS=value):
-            assert not yes(env_var_override='OVERRIDE_THIS')
+        monkeypatch.setenv('OVERRIDE_THIS', value)
+        assert not yes(env_var_override='OVERRIDE_THIS')
 
 
-def test_yes_env_default():
+def test_yes_env_default(monkeypatch):
     for value in DEFAULTISH:
-        with environment_variable(OVERRIDE_THIS=value):
-            assert yes(env_var_override='OVERRIDE_THIS', default=True)
-        with environment_variable(OVERRIDE_THIS=value):
-            assert not yes(env_var_override='OVERRIDE_THIS', default=False)
+        monkeypatch.setenv('OVERRIDE_THIS', value)
+        assert yes(env_var_override='OVERRIDE_THIS', default=True)
+        assert not yes(env_var_override='OVERRIDE_THIS', default=False)
 
 
 def test_yes_defaults():
diff --git a/src/borg/testsuite/upgrader.py b/src/borg/testsuite/upgrader.py
--- a/src/borg/testsuite/upgrader.py
+++ b/src/borg/testsuite/upgrader.py
@@ -98,7 +98,7 @@ def __init__(self, path):
 
 
 @pytest.fixture()
-def attic_key_file(attic_repo, tmpdir):
+def attic_key_file(attic_repo, tmpdir, monkeypatch):
     """
     create an attic key file from the given repo, in the keys
     subdirectory of the given tmpdir
@@ -113,13 +113,13 @@ def attic_key_file(attic_repo, tmpdir):
 
     # we use the repo dir for the created keyfile, because we do
     # not want to clutter existing keyfiles
-    os.environ['ATTIC_KEYS_DIR'] = keys_dir
+    monkeypatch.setenv('ATTIC_KEYS_DIR', keys_dir)
 
     # we use the same directory for the converted files, which
     # will clutter the previously created one, which we don't care
     # about anyways. in real runs, the original key will be retained.
-    os.environ['BORG_KEYS_DIR'] = keys_dir
-    os.environ['ATTIC_PASSPHRASE'] = 'test'
+    monkeypatch.setenv('BORG_KEYS_DIR', keys_dir)
+    monkeypatch.setenv('ATTIC_PASSPHRASE', 'test')
     return attic.key.KeyfileKey.create(attic_repo,
                                        MockArgs(keys_dir))
 


Test patch: