From fd20fd23bbe98fde050b3ff81c8bdc1e43e70664 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 9 Jul 2025 13:29:33 +0530 Subject: [PATCH] Use clean HOME and CONF and CACHE dirs when running Go tests --- kitty_tests/main.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/kitty_tests/main.py b/kitty_tests/main.py index be12eee90..f335a817f 100644 --- a/kitty_tests/main.py +++ b/kitty_tests/main.py @@ -12,7 +12,7 @@ import unittest from collections.abc import Callable, Generator, Iterator, Sequence from contextlib import contextmanager from functools import lru_cache -from tempfile import TemporaryDirectory +from tempfile import TemporaryDirectory, mkdtemp from threading import Thread from typing import ( Any, @@ -150,6 +150,16 @@ class GoProc(Thread): env['KITTY_PATH_TO_KITTY_EXE'] = kitty_exe() self.stdout = b'' self.start_time = time.monotonic() + self.tdir = mkdtemp(prefix='kitty-go-tests-') + env['HOME'] = self.tdir + if not env.get('GOCACHE') and (gop := os.path.expanduser('~/.cache/go-build')) and os.path.isdir(gop): + env['GOCACHE'] = gop + if not env.get('GOMODCACHE') and (gop := os.path.expanduser('~/go/pkg/mod')) and os.path.isdir(gop): + env['GOMODCACHE'] = gop + env['XDG_CONFIG_HOME'] = self.tdir + '/conf' + os.mkdir(env['XDG_CONFIG_HOME']) + env['XDG_CACHE_HOME'] = self.tdir + '/cache' + os.mkdir(env['XDG_CACHE_HOME']) self.proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) self.start() @@ -162,8 +172,11 @@ class GoProc(Thread): return self.proc.returncode def run(self) -> None: - self.stdout, _ = self.proc.communicate() - self.proc.stdout.close() + try: + self.stdout, _ = self.proc.communicate() + self.proc.stdout.close() + finally: + shutil.rmtree(self.tdir) def wait(self, timeout=None) -> None: try: