summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTom Scogland <scogland1@llnl.gov>2022-05-05 11:48:16 -0700
committerGitHub <noreply@github.com>2022-05-05 11:48:16 -0700
commit6898b7c2f6dafb36aa8387dc5cc5d6fcec287c7f (patch)
tree5a7577e2bf8c32034a1f00f5e52b07d8e1501291 /lib
parent28366489042d6ec3090e745c6b6ef9dcb49bb19f (diff)
downloadspack-6898b7c2f6dafb36aa8387dc5cc5d6fcec287c7f.tar.gz
spack-6898b7c2f6dafb36aa8387dc5cc5d6fcec287c7f.tar.bz2
spack-6898b7c2f6dafb36aa8387dc5cc5d6fcec287c7f.tar.xz
spack-6898b7c2f6dafb36aa8387dc5cc5d6fcec287c7f.zip
harden unit tests, enable basic parallelism (#29593)
* use the init.defaultBranch name, not master * make tcl and modules/common independent Both used to use not just the same directory, but the same *file* for their outputs. In parallel this can cause problems, but it can also accidentally allow expected failures to pass if the file is left around by mistake. * use a non-global misc_cache in tests * make pkg tests resilient to gitignore * make source cache and module directories non-global
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/cmd/pkg.py3
-rw-r--r--lib/spack/spack/test/conftest.py13
-rw-r--r--lib/spack/spack/test/data/config/config.yaml5
-rw-r--r--lib/spack/spack/test/data/config/modules.yaml3
-rw-r--r--lib/spack/spack/test/modules/common.py14
-rw-r--r--lib/spack/spack/test/modules/conftest.py14
-rw-r--r--lib/spack/spack/test/modules/tcl.py10
7 files changed, 39 insertions, 23 deletions
diff --git a/lib/spack/spack/test/cmd/pkg.py b/lib/spack/spack/test/cmd/pkg.py
index 352ffca4ac..b868c62c66 100644
--- a/lib/spack/spack/test/cmd/pkg.py
+++ b/lib/spack/spack/test/cmd/pkg.py
@@ -54,7 +54,8 @@ def mock_pkg_git_repo(tmpdir_factory):
git('init')
# initial commit with mock packages
- git('add', '.')
+ # the -f is necessary in case people ignore build-* in their ignores
+ git('add', '-f', '.')
git('config', 'user.email', 'testing@spack.io')
git('config', 'user.name', 'Spack Testing')
git('-c', 'commit.gpgsign=false', 'commit',
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index 11a24ba044..a10ccc7f0f 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -1335,7 +1335,16 @@ def mock_git_repository(tmpdir_factory):
tag = 'test-tag'
git('tag', tag)
- git('checkout', 'master')
+ try:
+ default_branch = git(
+ 'config',
+ '--get',
+ 'init.defaultBranch',
+ output=str,
+ ).strip()
+ except Exception:
+ default_branch = 'master'
+ git('checkout', default_branch)
r2_file = 'r2_file'
repodir.ensure(r2_file)
@@ -1357,7 +1366,7 @@ def mock_git_repository(tmpdir_factory):
# that revision/branch.
checks = {
'master': Bunch(
- revision='master', file=r0_file, args={'git': url}
+ revision=default_branch, file=r0_file, args={'git': url}
),
'branch': Bunch(
revision=branch, file=branch_file, args={
diff --git a/lib/spack/spack/test/data/config/config.yaml b/lib/spack/spack/test/data/config/config.yaml
index 43e8ad1abc..0ae86957db 100644
--- a/lib/spack/spack/test/data/config/config.yaml
+++ b/lib/spack/spack/test/data/config/config.yaml
@@ -7,9 +7,8 @@ config:
- $spack/lib/spack/spack/test/data/templates_again
build_stage:
- $tempdir/$user/spack-stage
- - ~/.spack/stage
- source_cache: $spack/var/spack/cache
- misc_cache: ~/.spack/cache
+ source_cache: $user_cache_path/source
+ misc_cache: $user_cache_path/cache
verify_ssl: true
checksum: true
dirty: false
diff --git a/lib/spack/spack/test/data/config/modules.yaml b/lib/spack/spack/test/data/config/modules.yaml
index e2ddd841c5..28e2ec91b3 100644
--- a/lib/spack/spack/test/data/config/modules.yaml
+++ b/lib/spack/spack/test/data/config/modules.yaml
@@ -17,6 +17,9 @@ modules:
default:
enable:
- tcl
+ roots:
+ tcl: $user_cache_path/tcl
+ lmod: $user_cache_path/lmod
prefix_inspections:
bin:
- PATH
diff --git a/lib/spack/spack/test/modules/common.py b/lib/spack/spack/test/modules/common.py
index 39619ce741..9eff0c23cc 100644
--- a/lib/spack/spack/test/modules/common.py
+++ b/lib/spack/spack/test/modules/common.py
@@ -46,20 +46,6 @@ def test_update_dictionary_extending_list():
@pytest.fixture()
-def mock_module_filename(monkeypatch, tmpdir):
- filename = str(tmpdir.join('module'))
- # Set for both module types so we can test both
- monkeypatch.setattr(spack.modules.lmod.LmodFileLayout,
- 'filename',
- filename)
- monkeypatch.setattr(spack.modules.tcl.TclFileLayout,
- 'filename',
- filename)
-
- yield filename
-
-
-@pytest.fixture()
def mock_module_defaults(monkeypatch):
def impl(*args):
# No need to patch both types because neither override base
diff --git a/lib/spack/spack/test/modules/conftest.py b/lib/spack/spack/test/modules/conftest.py
index 04e28f5f53..61fe4add0a 100644
--- a/lib/spack/spack/test/modules/conftest.py
+++ b/lib/spack/spack/test/modules/conftest.py
@@ -62,3 +62,17 @@ def factory(request):
return writer_cls(spec, module_set_name), spec
return _mock
+
+
+@pytest.fixture()
+def mock_module_filename(monkeypatch, tmpdir):
+ filename = str(tmpdir.join('module'))
+ # Set for both module types so we can test both
+ monkeypatch.setattr(spack.modules.lmod.LmodFileLayout,
+ 'filename',
+ filename)
+ monkeypatch.setattr(spack.modules.tcl.TclFileLayout,
+ 'filename',
+ filename)
+
+ yield filename
diff --git a/lib/spack/spack/test/modules/tcl.py b/lib/spack/spack/test/modules/tcl.py
index d9e4ad17bd..a8be4e87b6 100644
--- a/lib/spack/spack/test/modules/tcl.py
+++ b/lib/spack/spack/test/modules/tcl.py
@@ -22,7 +22,7 @@ pytestmark = pytest.mark.skipif(sys.platform == "win32",
reason="does not run on windows")
-@pytest.mark.usefixtures('config', 'mock_packages')
+@pytest.mark.usefixtures('config', 'mock_packages', 'mock_module_filename')
class TestTcl(object):
def test_simple_case(self, modulefile_content, module_configuration):
@@ -199,7 +199,9 @@ class TestTcl(object):
projection = writer.spec.format(writer.conf.projections['all'])
assert projection in writer.layout.use_name
- def test_invalid_naming_scheme(self, factory, module_configuration):
+ def test_invalid_naming_scheme(
+ self, factory, module_configuration, mock_module_filename
+ ):
"""Tests the evaluation of an invalid naming scheme."""
module_configuration('invalid_naming_scheme')
@@ -210,7 +212,9 @@ class TestTcl(object):
with pytest.raises(RuntimeError):
writer.layout.use_name
- def test_invalid_token_in_env_name(self, factory, module_configuration):
+ def test_invalid_token_in_env_name(
+ self, factory, module_configuration, mock_module_filename
+ ):
"""Tests setting environment variables with an invalid name."""
module_configuration('invalid_token_in_env_var_name')