Skip to content

Commit

Permalink
Ensure that certain test cleanup always happens, even if setUp fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjyw authored and Benjy committed May 5, 2015
1 parent ba7131d commit 2a3f0c5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/python/pants_test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ def setUp(self):
super(BaseTest, self).setUp()
Goal.clear()
self.real_build_root = BuildRoot().path

self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT'))
self.addCleanup(safe_rmtree, self.build_root)

self.pants_workdir = os.path.join(self.build_root, '.pants.d')
safe_mkdir(self.pants_workdir)

self.options = defaultdict(dict) # scope -> key-value mapping.
self.options[''] = {
'pants_workdir': self.pants_workdir,
Expand All @@ -127,7 +131,10 @@ def setUp(self):
'pants_configdir': os.path.join(self.build_root, 'config'),
'cache_key_gen_version': '0-test',
}

BuildRoot().path = self.build_root
self.addCleanup(BuildRoot().reset)

Subsystem.reset()

self.create_file('pants.ini')
Expand Down Expand Up @@ -219,9 +226,7 @@ def register(*rargs, **rkwargs):
return context

def tearDown(self):
BuildRoot().reset()
SourceRoot.reset()
safe_rmtree(self.build_root)
FilesystemBuildFile.clear_cache()

def target(self, spec):
Expand Down

0 comments on commit 2a3f0c5

Please sign in to comment.