Run py.test in clean cache directory

And finally remove XDG_CACHE_HOME=... in tox.ini.
This commit is contained in:
Takafumi Arakaki
2013-03-12 08:50:32 +01:00
parent 5c3252908f
commit cee167e3d2
4 changed files with 33 additions and 2 deletions

View File

@@ -1,2 +1,7 @@
[pytest] [pytest]
addopts = --assert=plain 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

View File

@@ -1,4 +1,8 @@
import os import os
import shutil
import tempfile
import pytest
from . import base from . import base
from . import run from . import run
@@ -57,3 +61,25 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize( metafunc.parametrize(
'refactor_case', 'refactor_case',
refactor.collect_dir_tests(base_dir, test_files)) 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)

View File

@@ -1,6 +1,8 @@
import os import os
import re import re
import pytest
from . import base from . import base
from .run import \ from .run import \
TEST_COMPLETIONS, TEST_DEFINITIONS, TEST_ASSIGNMENTS, TEST_USAGES TEST_COMPLETIONS, TEST_DEFINITIONS, TEST_ASSIGNMENTS, TEST_USAGES

View File

@@ -1,8 +1,6 @@
[tox] [tox]
envlist = py25, py26, py27, py32 envlist = py25, py26, py27, py32
[testenv] [testenv]
setenv =
XDG_CACHE_HOME={envtmpdir}/cache
deps = deps =
pytest pytest
commands = commands =