From a5c514ad6ee44b26de05519e6011aaa8623189a7 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 17 Jul 2024 13:04:40 +0200 Subject: [PATCH] [FIX] *bot: copy filestore (shared dir) when copying db Previously we would copy *only* the database itself, which is mostly not an issue, but when trying to debug *pages* using a browser, that browser tries to load various assets, which are looked up in the database, then in the filestore, where they are missing. This is not an issue in and of itself, but it triggers ugly tracebacks in the logs which is not convenient, and since 2ab06ca96b6b324823305c2cdf4f4447592926bf it fails the test even if the test would otherwise work. --- conftest.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/conftest.py b/conftest.py index 99b824e5..8e9d54ef 100644 --- a/conftest.py +++ b/conftest.py @@ -1,6 +1,7 @@ from __future__ import annotations import select +import shutil import threading from typing import Optional @@ -306,7 +307,8 @@ class DbDict(dict): self[module] = db return db - d = atexit.enter_context(tempfile.TemporaryDirectory()) + d = (self._shared_dir / f'shared-{module}') + d.mkdir() self[module] = db = 'template_%s' % uuid.uuid4() subprocess.run([ 'odoo', '--no-http', @@ -317,7 +319,7 @@ class DbDict(dict): '--log-level', 'warn' ], check=True, - env={**os.environ, 'XDG_DATA_HOME': d} + env={**os.environ, 'XDG_DATA_HOME': str(d)} ) f.write(db) f.flush() @@ -340,9 +342,18 @@ def dbcache(request, tmp_path_factory, addons_path): yield dbs @pytest.fixture -def db(request, module, dbcache): +def db(request, module, dbcache, tmpdir): + template_db = dbcache[module] rundb = str(uuid.uuid4()) - subprocess.run(['createdb', '-T', dbcache[module], rundb], check=True) + subprocess.run(['createdb', '-T', template_db, rundb], check=True) + share = tmpdir.mkdir('share') + shutil.copytree( + str(dbcache._shared_dir / f'shared-{module}'), + str(share), + dirs_exist_ok=True, + ) + (share / 'Odoo' / 'filestore' / template_db).rename( + share / 'Odoo' / 'filestore' / rundb) yield rundb @@ -464,7 +475,7 @@ def server(request, db, port, module, addons_path, tmpdir): **os.environ, # stop putting garbage in the user dirs, and potentially creating conflicts # TODO: way to override this with macOS? - 'XDG_DATA_HOME': str(tmpdir.mkdir('share')), + 'XDG_DATA_HOME': str(tmpdir / 'share'), 'XDG_CACHE_HOME': str(tmpdir.mkdir('cache')), }) os.close(w)