summaryrefslogtreecommitdiff
path: root/lib/spack/spack/test/install.py
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2017-10-15 23:59:53 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2017-10-17 01:26:31 -0700
commitd14816cbafdae7e78beee2910ec0827db16122ef (patch)
tree5dc265c0c1ee7e979dcbb51184f792f83a7361e3 /lib/spack/spack/test/install.py
parent44bebd7a8f0ed398abb12e20231e2acd2226c691 (diff)
downloadspack-d14816cbafdae7e78beee2910ec0827db16122ef.tar.gz
spack-d14816cbafdae7e78beee2910ec0827db16122ef.tar.bz2
spack-d14816cbafdae7e78beee2910ec0827db16122ef.tar.xz
spack-d14816cbafdae7e78beee2910ec0827db16122ef.zip
Spack tests no longer clutter var/spack/stage
- Tests use a session-scoped mock stage directory so as not to interfere with the real install. - Every test is forced to clean up after itself with an additional check. We now automatically assert that no new files have been added to `spack.stage_path` during each test. - This means that tests that fail installs now need to clean up their stages, but in all other cases the check is useful.
Diffstat (limited to 'lib/spack/spack/test/install.py')
-rw-r--r--lib/spack/spack/test/install.py54
1 files changed, 28 insertions, 26 deletions
diff --git a/lib/spack/spack/test/install.py b/lib/spack/spack/test/install.py
index 454adbac5e..cf08642dfa 100644
--- a/lib/spack/spack/test/install.py
+++ b/lib/spack/spack/test/install.py
@@ -69,46 +69,49 @@ class MockStage(object):
self.test_destroyed = False
def __enter__(self):
+ self.create()
return self
- def __exit__(self, *exc):
- return True
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ if exc_type is None:
+ self.destroy()
def destroy(self):
self.test_destroyed = True
self.wrapped_stage.destroy()
+ def create(self):
+ self.wrapped_stage.create()
+
def __getattr__(self, attr):
return getattr(self.wrapped_stage, attr)
def test_partial_install_delete_prefix_and_stage(install_mockery, mock_fetch):
- spec = Spec('canfail')
- spec.concretize()
+ spec = Spec('canfail').concretized()
pkg = spack.repo.get(spec)
remove_prefix = spack.package.Package.remove_prefix
instance_rm_prefix = pkg.remove_prefix
try:
+ pkg.succeed = False
spack.package.Package.remove_prefix = mock_remove_prefix
with pytest.raises(MockInstallError):
pkg.do_install()
assert os.path.isdir(pkg.prefix)
rm_prefix_checker = RemovePrefixChecker(instance_rm_prefix)
spack.package.Package.remove_prefix = rm_prefix_checker.remove_prefix
- setattr(pkg, 'succeed', True)
+
+ pkg.succeed = True
pkg.stage = MockStage(pkg.stage)
+
pkg.do_install(restage=True)
assert rm_prefix_checker.removed
assert pkg.stage.test_destroyed
assert pkg.installed
+
finally:
spack.package.Package.remove_prefix = remove_prefix
- pkg._stage = None
- try:
- delattr(pkg, 'succeed')
- except AttributeError:
- pass
def test_dont_add_patches_to_installed_package(install_mockery, mock_fetch):
@@ -141,53 +144,50 @@ def test_installed_dependency_request_conflicts(
dependent.concretize()
+@pytest.mark.disable_clean_stage_check
def test_partial_install_keep_prefix(install_mockery, mock_fetch):
- spec = Spec('canfail')
- spec.concretize()
+ spec = Spec('canfail').concretized()
pkg = spack.repo.get(spec)
+
# Normally the stage should start unset, but other tests set it
pkg._stage = None
remove_prefix = spack.package.Package.remove_prefix
try:
# If remove_prefix is called at any point in this test, that is an
# error
+ pkg.succeed = False # make the build fail
spack.package.Package.remove_prefix = mock_remove_prefix
with pytest.raises(spack.build_environment.ChildError):
pkg.do_install(keep_prefix=True)
assert os.path.exists(pkg.prefix)
- setattr(pkg, 'succeed', True)
+
+ pkg.succeed = True # make the build succeed
pkg.stage = MockStage(pkg.stage)
pkg.do_install(keep_prefix=True)
assert pkg.installed
assert not pkg.stage.test_destroyed
+
finally:
spack.package.Package.remove_prefix = remove_prefix
- pkg._stage = None
- try:
- delattr(pkg, 'succeed')
- except AttributeError:
- pass
def test_second_install_no_overwrite_first(install_mockery, mock_fetch):
- spec = Spec('canfail')
- spec.concretize()
+ spec = Spec('canfail').concretized()
pkg = spack.repo.get(spec)
remove_prefix = spack.package.Package.remove_prefix
try:
spack.package.Package.remove_prefix = mock_remove_prefix
- setattr(pkg, 'succeed', True)
+
+ pkg.succeed = True
pkg.do_install()
assert pkg.installed
+
# If Package.install is called after this point, it will fail
- delattr(pkg, 'succeed')
+ pkg.succeed = False
pkg.do_install()
+
finally:
spack.package.Package.remove_prefix = remove_prefix
- try:
- delattr(pkg, 'succeed')
- except AttributeError:
- pass
def test_store(install_mockery, mock_fetch):
@@ -196,9 +196,11 @@ def test_store(install_mockery, mock_fetch):
pkg.do_install()
+@pytest.mark.disable_clean_stage_check
def test_failing_build(install_mockery, mock_fetch):
spec = Spec('failing-build').concretized()
pkg = spec.package
+
with pytest.raises(spack.build_environment.ChildError):
pkg.do_install()