diff --git a/conftest.py b/conftest.py index e7cdeda2..45369d12 100644 --- a/conftest.py +++ b/conftest.py @@ -271,14 +271,18 @@ class DbDict(dict): self._adpath = adpath def __missing__(self, module): self[module] = db = 'template_%s' % uuid.uuid4() - subprocess.run([ - 'odoo', '--no-http', - '--addons-path', self._adpath, - '-d', db, '-i', module + ',auth_oauth', - '--max-cron-threads', '0', - '--stop-after-init', - '--log-level', 'warn' - ], check=True) + with tempfile.TemporaryDirectory() as d: + subprocess.run([ + 'odoo', '--no-http', + '--addons-path', self._adpath, + '-d', db, '-i', module + ',auth_oauth', + '--max-cron-threads', '0', + '--stop-after-init', + '--log-level', 'warn' + ], + check=True, + env={**os.environ, 'XDG_DATA_HOME': d} + ) return db @pytest.fixture(scope='session') @@ -355,7 +359,7 @@ def from_role(_): yield dummy_addons_path @pytest.fixture -def server(request, db, port, module, dummy_addons_path): +def server(request, db, port, module, dummy_addons_path, tmpdir): log_handlers = [ 'odoo.modules.loading:WARNING', ] @@ -372,7 +376,13 @@ def server(request, db, port, module, dummy_addons_path): '-d', db, '--max-cron-threads', '0', # disable cron threads (we're running crons by hand) *itertools.chain.from_iterable(('--log-handler', h) for h in log_handlers), - ]) + ], env={ + **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_CACHE_HOME': str(tmpdir.mkdir('cache')), + }) try: wait_for_server(db, port, p, module) diff --git a/forwardport/tests/conftest.py b/forwardport/tests/conftest.py index b8e530bc..408345af 100644 --- a/forwardport/tests/conftest.py +++ b/forwardport/tests/conftest.py @@ -1,12 +1,8 @@ # -*- coding: utf-8 -*- -import pathlib import re -import requests -from shutil import rmtree import pytest - -from odoo.tools.appdirs import user_cache_dir +import requests @pytest.fixture def default_crons(): @@ -47,20 +43,6 @@ def _check_scopes(config): assert token_scopes >= required_scopes, \ "%s should have scopes %s, found %s" % (section, token_scopes, required_scopes) -@pytest.fixture(autouse=True) -def _cleanup_cache(config, users): - """ forwardport has a repo cache which it assumes is unique per name - but tests always use the same repo paths / names for different repos - (the repos get re-created), leading to divergent repo histories. - - So clear cache after each test, two tests should not share repos. - """ - yield - cache_root = pathlib.Path(user_cache_dir('forwardport')) - rmtree(cache_root / config['github']['owner'], ignore_errors=True) - for login in users.values(): - rmtree(cache_root / login, ignore_errors=True) - @pytest.fixture() def module(): """ When a test function is (going to be) run, selects the containing