diff --git a/tests/python/pants_test/backend/python/tasks/test_gather_sources.py b/tests/python/pants_test/backend/python/tasks/test_gather_sources.py index db9a0f97518..b95d0bb648a 100644 --- a/tests/python/pants_test/backend/python/tasks/test_gather_sources.py +++ b/tests/python/pants_test/backend/python/tasks/test_gather_sources.py @@ -17,6 +17,7 @@ from pants.build_graph.files import Files from pants.build_graph.resources import Resources from pants.source.source_root import SourceRootConfig +from pants.util.contextutil import temporary_dir from pants_test.task_test_base import TaskTestBase @@ -106,19 +107,22 @@ def test_gather_files(self): self._assert_content_not_in_pex(pex, self.resources) def _gather_sources(self, target_roots): - context = self.context(target_roots=target_roots, for_subsystems=[PythonSetup, PythonRepos]) - - # We must get an interpreter via the cache, instead of using PythonInterpreter.get() directly, - # to ensure that the interpreter has setuptools and wheel support. - interpreter = PythonInterpreter.get() - interpreter_cache = PythonInterpreterCache(PythonSetup.global_instance(), - PythonRepos.global_instance(), - logger=context.log.debug) - interpreters = interpreter_cache.setup(paths=[os.path.dirname(interpreter.binary)], - filters=[str(interpreter.identity.requirement)]) - context.products.get_data(PythonInterpreter, lambda: interpreters[0]) - - task = self.create_task(context) - task.execute() - - return context.products.get_data(GatherSources.PYTHON_SOURCES) + with temporary_dir() as cache_dir: + context = self.context(target_roots=target_roots, + for_subsystems=[PythonSetup, PythonRepos], + options={PythonSetup.options_scope: {'interpreter_cache_dir': cache_dir}}) + + # We must get an interpreter via the cache, instead of using PythonInterpreter.get() directly, + # to ensure that the interpreter has setuptools and wheel support. + interpreter = PythonInterpreter.get() + interpreter_cache = PythonInterpreterCache(PythonSetup.global_instance(), + PythonRepos.global_instance(), + logger=context.log.debug) + interpreters = interpreter_cache.setup(paths=[os.path.dirname(interpreter.binary)], + filters=[str(interpreter.identity.requirement)]) + context.products.get_data(PythonInterpreter, lambda: interpreters[0]) + + task = self.create_task(context) + task.execute() + + return context.products.get_data(GatherSources.PYTHON_SOURCES) diff --git a/tests/python/pants_test/backend/python/tasks/test_resolve_requirements.py b/tests/python/pants_test/backend/python/tasks/test_resolve_requirements.py index a6030142fb9..2799d3a29b3 100644 --- a/tests/python/pants_test/backend/python/tasks/test_resolve_requirements.py +++ b/tests/python/pants_test/backend/python/tasks/test_resolve_requirements.py @@ -16,7 +16,7 @@ from pants.backend.python.targets.python_requirement_library import PythonRequirementLibrary from pants.backend.python.tasks.resolve_requirements import ResolveRequirements from pants.base.build_environment import get_buildroot -from pants.util.contextutil import temporary_file +from pants.util.contextutil import temporary_dir, temporary_file from pants.util.process_handler import subprocess from pants_test.task_test_base import TaskTestBase @@ -114,23 +114,26 @@ def _fake_target(self, spec, requirement_strs): requirements=requirements) def _resolve_requirements(self, target_roots, options=None): - context = self.context(target_roots=target_roots, options=options, - for_subsystems=[PythonSetup, PythonRepos]) - - # We must get an interpreter via the cache, instead of using PythonInterpreter.get() directly, - # to ensure that the interpreter has setuptools and wheel support. - interpreter = PythonInterpreter.get() - interpreter_cache = PythonInterpreterCache(PythonSetup.global_instance(), - PythonRepos.global_instance(), - logger=context.log.debug) - interpreters = interpreter_cache.setup(paths=[os.path.dirname(interpreter.binary)], - filters=[str(interpreter.identity.requirement)]) - context.products.get_data(PythonInterpreter, lambda: interpreters[0]) - - task = self.create_task(context) - task.execute() - - return context.products.get_data(ResolveRequirements.REQUIREMENTS_PEX) + with temporary_dir() as cache_dir: + options = options or {} + options.setdefault(PythonSetup.options_scope, {})['interpreter_cache_dir'] = cache_dir + context = self.context(target_roots=target_roots, options=options, + for_subsystems=[PythonSetup, PythonRepos]) + + # We must get an interpreter via the cache, instead of using PythonInterpreter.get() directly, + # to ensure that the interpreter has setuptools and wheel support. + interpreter = PythonInterpreter.get() + interpreter_cache = PythonInterpreterCache(PythonSetup.global_instance(), + PythonRepos.global_instance(), + logger=context.log.debug) + interpreters = interpreter_cache.setup(paths=[os.path.dirname(interpreter.binary)], + filters=[str(interpreter.identity.requirement)]) + context.products.get_data(PythonInterpreter, lambda: interpreters[0]) + + task = self.create_task(context) + task.execute() + + return context.products.get_data(ResolveRequirements.REQUIREMENTS_PEX) def _exercise_module(self, pex, expected_module): with temporary_file() as f: