From cee167e3d29c951e51894291eb65ec700082a874 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Tue, 12 Mar 2013 08:50:32 +0100 Subject: [PATCH] Run py.test in clean cache directory And finally remove XDG_CACHE_HOME=... in tox.ini. --- pytest.ini | 5 +++++ test/conftest.py | 26 ++++++++++++++++++++++++++ test/test_integration.py | 2 ++ tox.ini | 2 -- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pytest.ini b/pytest.ini index 2ce9da86..4afbf164 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,7 @@ [pytest] addopts = --assert=plain + +# Activate `clean_jedi_cache` fixture for all tests. This should be +# fine as long as we are using `clean_jedi_cache` as a session scoped +# fixture. +usefixtures = clean_jedi_cache diff --git a/test/conftest.py b/test/conftest.py index 8d94cbd3..4cb2f4e5 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,4 +1,8 @@ import os +import shutil +import tempfile + +import pytest from . import base from . import run @@ -57,3 +61,25 @@ def pytest_generate_tests(metafunc): metafunc.parametrize( 'refactor_case', refactor.collect_dir_tests(base_dir, test_files)) + + +@pytest.fixture(scope='session') +def clean_jedi_cache(request): + """ + Set `jedi.settings.cache_directory` to a temporary directory during test. + + Note that you can't use built-in `tmpdir` and `monkeypatch` + fixture here because their scope is 'function', which is not used + in 'session' scope fixture. + + This fixture is activated in ../pytest.ini. + """ + settings = base.jedi.settings + old = settings.cache_directory + tmp = tempfile.mkdtemp(prefix='jedi-test-') + settings.cache_directory = tmp + + @request.addfinalizer + def restore(): + settings.cache_directory = old + shutil.rmtree(tmp) diff --git a/test/test_integration.py b/test/test_integration.py index f348689d..b3baf336 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -1,6 +1,8 @@ import os import re +import pytest + from . import base from .run import \ TEST_COMPLETIONS, TEST_DEFINITIONS, TEST_ASSIGNMENTS, TEST_USAGES diff --git a/tox.ini b/tox.ini index afcc4cbf..55022b23 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,6 @@ [tox] envlist = py25, py26, py27, py32 [testenv] -setenv = - XDG_CACHE_HOME={envtmpdir}/cache deps = pytest commands =