Skip to content

Commit 965e002

Browse files
Fix / enable parallel unit tests
This commit enables parallel unit tests in ramble. The spack_runner tests were moved under the standard unit test directory, which allows them to use fixtures defined in the standard conftest.py file. Additionally, a new fixture is defined in conftest.py to help fix thread issues with the logger utility.
1 parent 6a8334b commit 965e002

File tree

7 files changed

+136
-83
lines changed

7 files changed

+136
-83
lines changed

.coveragerc

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/ramble/ramble/test/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@ def no_path_access(monkeypatch):
494494
monkeypatch.setattr(os, "access", _can_access)
495495

496496

497+
@pytest.fixture(scope="function", autouse=True)
498+
def print_all_logs(monkeypatch):
499+
import ramble.util.logger
500+
501+
monkeypatch.setattr(ramble.util.logger.logger, "msg", ramble.util.logger.logger.all_msg)
502+
503+
497504
##########
498505
# Fake archives and repositories
499506
##########
Lines changed: 49 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@
1818
)
1919

2020

21-
def test_env_create(tmpdir):
21+
def test_env_create(tmpdir, request):
2222
try:
23-
env_path = tmpdir.join("spack-env")
23+
env_path = tmpdir.join(request.node.name)
2424
sr = SpackRunner()
2525
sr.create_env(env_path)
2626
except RunnerError as e:
2727
pytest.skip("%s" % e)
2828

2929

30-
def test_env_activate(tmpdir):
30+
def test_env_activate(tmpdir, request):
3131
try:
32-
env_path = tmpdir.join("spack-env")
32+
env_path = tmpdir.join(request.node.name)
3333
sr = SpackRunner()
3434
sr.create_env(env_path)
3535
sr.activate()
3636
except RunnerError as e:
3737
pytest.skip("%s" % e)
3838

3939

40-
def test_env_deactivate(tmpdir):
40+
def test_env_deactivate(tmpdir, request):
4141
try:
42-
env_path = tmpdir.join("spack-env")
42+
env_path = tmpdir.join(request.node.name)
4343
sr = SpackRunner()
4444
sr.create_env(env_path)
4545
sr.activate()
@@ -48,9 +48,9 @@ def test_env_deactivate(tmpdir):
4848
pytest.skip("%s" % e)
4949

5050

51-
def test_env_add(tmpdir):
51+
def test_env_add(tmpdir, request):
5252
try:
53-
env_path = tmpdir.join("spack-env")
53+
env_path = tmpdir.join(request.node.name)
5454
sr = SpackRunner()
5555
sr.create_env(env_path)
5656
sr.activate()
@@ -60,9 +60,9 @@ def test_env_add(tmpdir):
6060
pytest.skip("%s" % e)
6161

6262

63-
def test_env_concretize(tmpdir):
63+
def test_env_concretize(tmpdir, request):
6464
try:
65-
env_path = tmpdir.join("spack-env")
65+
env_path = tmpdir.join(request.node.name)
6666
sr = SpackRunner()
6767
sr.create_env(env_path)
6868
sr.activate()
@@ -75,11 +75,11 @@ def test_env_concretize(tmpdir):
7575
pytest.skip("%s" % e)
7676

7777

78-
def test_env_concretize_skips_already_concretized_envs(tmpdir, capsys):
78+
def test_env_concretize_skips_already_concretized_envs(tmpdir, capsys, request):
7979
import time
8080

8181
try:
82-
env_path = tmpdir.join("spack-env")
82+
env_path = tmpdir.join(request.node.name)
8383
sr = SpackRunner()
8484
sr.create_env(env_path)
8585
sr.activate()
@@ -103,8 +103,7 @@ def test_env_concretize_skips_already_concretized_envs(tmpdir, capsys):
103103
output = capsys.readouterr()
104104
assert f"Environment {env_path} will not be regenerated" in output.out
105105
assert (
106-
f"Environment {env_path} is already concretized. Skipping concretize..."
107-
in output.out
106+
f"Environment {env_path} is already concretized. Skipping concretize..." in output.out
108107
)
109108

110109
sr.deactivate()
@@ -114,9 +113,9 @@ def test_env_concretize_skips_already_concretized_envs(tmpdir, capsys):
114113
pytest.skip("%s" % e)
115114

116115

117-
def test_env_install(tmpdir, capsys):
116+
def test_env_install(tmpdir, capsys, request):
118117
try:
119-
env_path = str(tmpdir.join("spack-env"))
118+
env_path = str(tmpdir.join(request.node.name))
120119
# Dry run so we don't actually install zlib
121120
sr = SpackRunner(dry_run=True)
122121
sr.create_env(env_path)
@@ -135,16 +134,16 @@ def test_env_install(tmpdir, capsys):
135134

136135
assert os.path.exists(env_file)
137136

138-
with open(env_file, "r") as f:
137+
with open(env_file) as f:
139138
assert "zlib" in f.read()
140139

141140
except RunnerError as e:
142141
pytest.skip("%s" % e)
143142

144143

145-
def test_env_configs_apply(tmpdir, capsys):
144+
def test_env_configs_apply(tmpdir, capsys, request):
146145
try:
147-
env_path = str(tmpdir.join("spack-env"))
146+
env_path = str(tmpdir.join(request.node.name))
148147
# Dry run so we don't actually install zlib
149148
sr = SpackRunner(dry_run=True)
150149
sr.create_env(env_path)
@@ -154,17 +153,15 @@ def test_env_configs_apply(tmpdir, capsys):
154153
sr.generate_env_file()
155154

156155
captured = capsys.readouterr()
157-
assert (
158-
"with args: ['config', 'add', 'config:debug:true']" in captured.out
159-
)
156+
assert "with args: ['config', 'add', 'config:debug:true']" in captured.out
160157

161158
sr.deactivate()
162159

163160
env_file = os.path.join(env_path, "spack.yaml")
164161

165162
assert os.path.exists(env_file)
166163

167-
with open(env_file, "r") as f:
164+
with open(env_file) as f:
168165
data = f.read()
169166
assert "zlib" in data
170167
assert "debug: true" in data
@@ -173,9 +170,9 @@ def test_env_configs_apply(tmpdir, capsys):
173170
pytest.skip("%s" % e)
174171

175172

176-
def test_default_concretize_flags(tmpdir, capsys):
173+
def test_default_concretize_flags(tmpdir, capsys, request):
177174
try:
178-
env_path = tmpdir.join("spack-env")
175+
env_path = tmpdir.join(request.node.name)
179176
sr = SpackRunner(dry_run=True)
180177
sr.create_env(env_path)
181178
sr.activate()
@@ -196,14 +193,10 @@ def test_default_concretize_flags(tmpdir, capsys):
196193
("prefix", "time", "would run time"),
197194
],
198195
)
199-
def test_config_concretize_attribute(
200-
tmpdir, capsys, attr, value, expected_str
201-
):
196+
def test_config_concretize_attribute(tmpdir, capsys, attr, value, expected_str, request):
202197
try:
203-
env_path = tmpdir.join("spack-env")
204-
with ramble.config.override(
205-
"config:spack", {"concretize": {attr: value}}
206-
):
198+
env_path = tmpdir.join(request.node.name)
199+
with ramble.config.override("config:spack", {"concretize": {attr: value}}):
207200
sr = SpackRunner(dry_run=True)
208201
sr.create_env(env_path)
209202
sr.activate()
@@ -217,9 +210,9 @@ def test_config_concretize_attribute(
217210
pytest.skip("%s" % e)
218211

219212

220-
def test_default_install_flags(tmpdir, capsys):
213+
def test_default_install_flags(tmpdir, capsys, request):
221214
try:
222-
env_path = tmpdir.join("spack-env")
215+
env_path = tmpdir.join(request.node.name)
223216
sr = SpackRunner(dry_run=True)
224217
sr.create_env(env_path)
225218
sr.activate()
@@ -248,12 +241,10 @@ def test_default_install_flags(tmpdir, capsys):
248241
("prefix", "time", "would run time"),
249242
],
250243
)
251-
def test_config_install_attribute(tmpdir, capsys, attr, value, expected_str):
244+
def test_config_install_attribute(tmpdir, capsys, attr, value, expected_str, request):
252245
try:
253-
env_path = tmpdir.join("spack-env")
254-
with ramble.config.override(
255-
"config:spack", {"install": {attr: value}}
256-
):
246+
env_path = tmpdir.join(request.node.name)
247+
with ramble.config.override("config:spack", {"install": {attr: value}}):
257248
sr = SpackRunner(dry_run=True)
258249
sr.create_env(env_path)
259250
sr.activate()
@@ -268,9 +259,9 @@ def test_config_install_attribute(tmpdir, capsys, attr, value, expected_str):
268259
pytest.skip("%s" % e)
269260

270261

271-
def test_env_include(tmpdir, capsys):
262+
def test_env_include(tmpdir, capsys, request):
272263
try:
273-
env_path = tmpdir.join("spack-env")
264+
env_path = tmpdir.join(request.node.name)
274265
sr = SpackRunner(dry_run=True)
275266
sr.create_env(env_path)
276267
sr.activate()
@@ -282,15 +273,15 @@ def test_env_include(tmpdir, capsys):
282273
sr.generate_env_file()
283274
sr.concretize()
284275

285-
with open(os.path.join(env_path, "spack.yaml"), "r") as f:
276+
with open(os.path.join(env_path, "spack.yaml")) as f:
286277
data = f.read()
287278
assert good_include_path in data
288279
assert bad_include_path not in data
289280
except RunnerError as e:
290281
pytest.skip("%s" % e)
291282

292283

293-
def test_new_compiler_installs(tmpdir, capsys):
284+
def test_new_compiler_installs(tmpdir, capsys, request):
294285

295286
import os
296287

@@ -335,9 +326,7 @@ def test_new_compiler_installs(tmpdir, capsys):
335326
f.write(compilers_config)
336327

337328
config_path = os.getcwd()
338-
with ramble.config.override(
339-
"config:spack", {"global": {"flags": f"-C {config_path}"}}
340-
):
329+
with ramble.config.override("config:spack", {"global": {"flags": f"-C {config_path}"}}):
341330
try:
342331
sr = SpackRunner(dry_run=True)
343332
sr.create_env(os.getcwd())
@@ -348,15 +337,12 @@ def test_new_compiler_installs(tmpdir, capsys):
348337
sr.install_compiler("[email protected]")
349338
captured = capsys.readouterr()
350339

351-
assert (
352-
"[email protected] is already an available compiler"
353-
in captured.out
354-
)
340+
assert "[email protected] is already an available compiler" in captured.out
355341
except RunnerError as e:
356342
pytest.skip("%s" % e)
357343

358344

359-
def test_external_env_copies(tmpdir):
345+
def test_external_env_copies(tmpdir, request):
360346
src_spack_yaml = """
361347
spack:
362348
specs: [ 'zlib' ]
@@ -434,13 +420,13 @@ def test_external_env_copies(tmpdir):
434420

435421
assert os.path.exists(os.path.join(generated_env, "spack.yaml"))
436422

437-
with open(os.path.join(generated_env, "spack.yaml"), "r") as f:
423+
with open(os.path.join(generated_env, "spack.yaml")) as f:
438424
assert "zlib" in f.read()
439425
except RunnerError as e:
440426
pytest.skip("%s" % e)
441427

442428

443-
def test_configs_apply_to_external_env(tmpdir):
429+
def test_configs_apply_to_external_env(tmpdir, request):
444430
src_spack_yaml = """
445431
spack:
446432
specs: [ 'zlib' ]
@@ -459,7 +445,7 @@ def test_configs_apply_to_external_env(tmpdir):
459445

460446
assert os.path.exists(os.path.join(generated_env, "spack.yaml"))
461447

462-
with open(os.path.join(generated_env, "spack.yaml"), "r") as f:
448+
with open(os.path.join(generated_env, "spack.yaml")) as f:
463449
data = f.read()
464450
assert "zlib" in data
465451
assert "config:" in data
@@ -468,7 +454,7 @@ def test_configs_apply_to_external_env(tmpdir):
468454
pytest.skip("%s" % e)
469455

470456

471-
def test_invalid_external_env_errors(tmpdir):
457+
def test_invalid_external_env_errors(tmpdir, request):
472458
with tmpdir.as_cwd():
473459
try:
474460
sr = SpackRunner(dry_run=True)
@@ -487,9 +473,7 @@ def test_invalid_external_env_errors(tmpdir):
487473
("flags", "--scope site", "'--scope', 'site'"),
488474
],
489475
)
490-
def test_config_compiler_find_attribute(
491-
tmpdir, capsys, attr, value, expected_str
492-
):
476+
def test_config_compiler_find_attribute(tmpdir, capsys, attr, value, expected_str, request):
493477

494478
import os
495479

@@ -517,12 +501,8 @@ def test_config_compiler_find_attribute(
517501
f.write(compilers_config)
518502

519503
config_path = os.getcwd()
520-
with ramble.config.override(
521-
"config:spack", {"global": {"flags": f"-C {config_path}"}}
522-
):
523-
with ramble.config.override(
524-
"config:spack", {"compiler_find": {attr: value}}
525-
):
504+
with ramble.config.override("config:spack", {"global": {"flags": f"-C {config_path}"}}):
505+
with ramble.config.override("config:spack", {"compiler_find": {attr: value}}):
526506
try:
527507
sr = SpackRunner(dry_run=True)
528508
sr.create_env(os.getcwd())
@@ -536,28 +516,24 @@ def test_config_compiler_find_attribute(
536516
pytest.skip("%s" % e)
537517

538518

539-
def test_env_create_no_view(tmpdir):
519+
def test_env_create_no_view(tmpdir, request):
540520

541521
import os
542522

543523
with tmpdir.as_cwd():
544-
with ramble.config.override(
545-
"config:spack", {"env_create": {"flags": "--without-view"}}
546-
):
524+
with ramble.config.override("config:spack", {"env_create": {"flags": "--without-view"}}):
547525
try:
548526
sr = SpackRunner()
549527
sr.create_env(os.getcwd())
550528

551-
assert not os.path.exists(
552-
os.path.join(os.getcwd(), ".spack-env", "view")
553-
)
529+
assert not os.path.exists(os.path.join(os.getcwd(), ".spack-env", "view"))
554530
except RunnerError as e:
555531
pytest.skip("%s" % e)
556532

557533

558-
def test_multiword_args(tmpdir, capsys):
534+
def test_multiword_args(tmpdir, capsys, request):
559535
try:
560-
env_path = tmpdir.join("spack-env")
536+
env_path = tmpdir.join(request.node.name)
561537
with ramble.config.override(
562538
"config:spack",
563539
{"install": {"flags": 'install="-multiword -args"'}},

0 commit comments

Comments
 (0)