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
This commit is contained in:
parent
2836648904
commit
6898b7c2f6
@ -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',
|
||||
|
@ -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={
|
||||
|
@ -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
|
||||
|
@ -17,6 +17,9 @@ modules:
|
||||
default:
|
||||
enable:
|
||||
- tcl
|
||||
roots:
|
||||
tcl: $user_cache_path/tcl
|
||||
lmod: $user_cache_path/lmod
|
||||
prefix_inspections:
|
||||
bin:
|
||||
- PATH
|
||||
|
@ -45,20 +45,6 @@ def test_update_dictionary_extending_list():
|
||||
assert target['baz'] == 'foobaz'
|
||||
|
||||
|
||||
@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):
|
||||
|
@ -62,3 +62,17 @@ def _mock(spec_string, module_set_name='default'):
|
||||
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
|
||||
|
@ -22,7 +22,7 @@
|
||||
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 @@ def test_projections_all(self, factory, module_configuration):
|
||||
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 @@ def test_invalid_naming_scheme(self, factory, module_configuration):
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user