commit:     7a535fb3d2315fb6b73f3346fbd53468e48ccbfc
Author:     Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Mon Jan 22 03:20:33 2024 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Tue Jan 23 08:38:52 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=7a535fb3

fix: suppress $HOME for tests.

Suppressing $HOME is necessary for hygenic tests; to avoid
anything in the dev's environment becoming relied upon for
the test passing.

A slightly more salient point for me; every `git commit` test
was asking for my gpg unlock for git commits; obviously annoying,
also obviously unhygenic (I could have modified default git commit
template for example).

Signed-off-by: Brian Harring <ferringb <AT> gmail.com>

 src/pkgcore/pytest/plugin.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/pkgcore/pytest/plugin.py b/src/pkgcore/pytest/plugin.py
index 0579a45ad..d7231dd3c 100644
--- a/src/pkgcore/pytest/plugin.py
+++ b/src/pkgcore/pytest/plugin.py
@@ -41,6 +41,8 @@ class GitRepo:
                 self.add(pjoin(self.path, ".init"), create=True)
 
     def run(self, cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, 
**kwargs):
+        env = os.environ.copy()
+        env["HOME"] = self.path
         return subprocess.run(
             cmd,
             cwd=self.path,
@@ -48,6 +50,7 @@ class GitRepo:
             check=True,
             stdout=stdout,
             stderr=stderr,
+            env=env,
             **kwargs,
         )
 

Reply via email to