Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix / enable parallel unit tests #745

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .coveragerc

This file was deleted.

7 changes: 7 additions & 0 deletions lib/ramble/ramble/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ def no_path_access(monkeypatch):
monkeypatch.setattr(os, "access", _can_access)


@pytest.fixture(scope="function", autouse=True)
def print_all_logs(monkeypatch):
import ramble.util.logger

monkeypatch.setattr(ramble.util.logger.logger, "msg", ramble.util.logger.logger.all_msg)


##########
# Fake archives and repositories
##########
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@
)


def test_env_create(tmpdir):
def test_env_create(tmpdir, request):
try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
sr = SpackRunner()
sr.create_env(env_path)
except RunnerError as e:
pytest.skip("%s" % e)


def test_env_activate(tmpdir):
def test_env_activate(tmpdir, request):
try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
sr = SpackRunner()
sr.create_env(env_path)
sr.activate()
except RunnerError as e:
pytest.skip("%s" % e)


def test_env_deactivate(tmpdir):
def test_env_deactivate(tmpdir, request):
try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
sr = SpackRunner()
sr.create_env(env_path)
sr.activate()
Expand All @@ -48,9 +48,9 @@ def test_env_deactivate(tmpdir):
pytest.skip("%s" % e)


def test_env_add(tmpdir):
def test_env_add(tmpdir, request):
try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
sr = SpackRunner()
sr.create_env(env_path)
sr.activate()
Expand All @@ -60,9 +60,9 @@ def test_env_add(tmpdir):
pytest.skip("%s" % e)


def test_env_concretize(tmpdir):
def test_env_concretize(tmpdir, request):
try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
sr = SpackRunner()
sr.create_env(env_path)
sr.activate()
Expand All @@ -75,11 +75,11 @@ def test_env_concretize(tmpdir):
pytest.skip("%s" % e)


def test_env_concretize_skips_already_concretized_envs(tmpdir, capsys):
def test_env_concretize_skips_already_concretized_envs(tmpdir, capsys, request):
import time

try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
sr = SpackRunner()
sr.create_env(env_path)
sr.activate()
Expand All @@ -103,8 +103,7 @@ def test_env_concretize_skips_already_concretized_envs(tmpdir, capsys):
output = capsys.readouterr()
assert f"Environment {env_path} will not be regenerated" in output.out
assert (
f"Environment {env_path} is already concretized. Skipping concretize..."
in output.out
f"Environment {env_path} is already concretized. Skipping concretize..." in output.out
)

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


def test_env_install(tmpdir, capsys):
def test_env_install(tmpdir, capsys, request):
try:
env_path = str(tmpdir.join("spack-env"))
env_path = str(tmpdir.join(request.node.name))
# Dry run so we don't actually install zlib
sr = SpackRunner(dry_run=True)
sr.create_env(env_path)
Expand All @@ -135,16 +134,16 @@ def test_env_install(tmpdir, capsys):

assert os.path.exists(env_file)

with open(env_file, "r") as f:
with open(env_file) as f:
assert "zlib" in f.read()

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


def test_env_configs_apply(tmpdir, capsys):
def test_env_configs_apply(tmpdir, capsys, request):
try:
env_path = str(tmpdir.join("spack-env"))
env_path = str(tmpdir.join(request.node.name))
# Dry run so we don't actually install zlib
sr = SpackRunner(dry_run=True)
sr.create_env(env_path)
Expand All @@ -154,17 +153,15 @@ def test_env_configs_apply(tmpdir, capsys):
sr.generate_env_file()

captured = capsys.readouterr()
assert (
"with args: ['config', 'add', 'config:debug:true']" in captured.out
)
assert "with args: ['config', 'add', 'config:debug:true']" in captured.out

sr.deactivate()

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

assert os.path.exists(env_file)

with open(env_file, "r") as f:
with open(env_file) as f:
data = f.read()
assert "zlib" in data
assert "debug: true" in data
Expand All @@ -173,9 +170,9 @@ def test_env_configs_apply(tmpdir, capsys):
pytest.skip("%s" % e)


def test_default_concretize_flags(tmpdir, capsys):
def test_default_concretize_flags(tmpdir, capsys, request):
try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
sr = SpackRunner(dry_run=True)
sr.create_env(env_path)
sr.activate()
Expand All @@ -196,14 +193,10 @@ def test_default_concretize_flags(tmpdir, capsys):
("prefix", "time", "would run time"),
],
)
def test_config_concretize_attribute(
tmpdir, capsys, attr, value, expected_str
):
def test_config_concretize_attribute(tmpdir, capsys, attr, value, expected_str, request):
try:
env_path = tmpdir.join("spack-env")
with ramble.config.override(
"config:spack", {"concretize": {attr: value}}
):
env_path = tmpdir.join(request.node.name)
with ramble.config.override("config:spack", {"concretize": {attr: value}}):
sr = SpackRunner(dry_run=True)
sr.create_env(env_path)
sr.activate()
Expand All @@ -217,9 +210,9 @@ def test_config_concretize_attribute(
pytest.skip("%s" % e)


def test_default_install_flags(tmpdir, capsys):
def test_default_install_flags(tmpdir, capsys, request):
try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
sr = SpackRunner(dry_run=True)
sr.create_env(env_path)
sr.activate()
Expand Down Expand Up @@ -248,12 +241,10 @@ def test_default_install_flags(tmpdir, capsys):
("prefix", "time", "would run time"),
],
)
def test_config_install_attribute(tmpdir, capsys, attr, value, expected_str):
def test_config_install_attribute(tmpdir, capsys, attr, value, expected_str, request):
try:
env_path = tmpdir.join("spack-env")
with ramble.config.override(
"config:spack", {"install": {attr: value}}
):
env_path = tmpdir.join(request.node.name)
with ramble.config.override("config:spack", {"install": {attr: value}}):
sr = SpackRunner(dry_run=True)
sr.create_env(env_path)
sr.activate()
Expand All @@ -268,9 +259,9 @@ def test_config_install_attribute(tmpdir, capsys, attr, value, expected_str):
pytest.skip("%s" % e)


def test_env_include(tmpdir, capsys):
def test_env_include(tmpdir, capsys, request):
try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
sr = SpackRunner(dry_run=True)
sr.create_env(env_path)
sr.activate()
Expand All @@ -282,15 +273,15 @@ def test_env_include(tmpdir, capsys):
sr.generate_env_file()
sr.concretize()

with open(os.path.join(env_path, "spack.yaml"), "r") as f:
with open(os.path.join(env_path, "spack.yaml")) as f:
data = f.read()
assert good_include_path in data
assert bad_include_path not in data
except RunnerError as e:
pytest.skip("%s" % e)


def test_new_compiler_installs(tmpdir, capsys):
def test_new_compiler_installs(tmpdir, capsys, request):

import os

Expand Down Expand Up @@ -335,9 +326,7 @@ def test_new_compiler_installs(tmpdir, capsys):
f.write(compilers_config)

config_path = os.getcwd()
with ramble.config.override(
"config:spack", {"global": {"flags": f"-C {config_path}"}}
):
with ramble.config.override("config:spack", {"global": {"flags": f"-C {config_path}"}}):
try:
sr = SpackRunner(dry_run=True)
sr.create_env(os.getcwd())
Expand All @@ -348,15 +337,12 @@ def test_new_compiler_installs(tmpdir, capsys):
sr.install_compiler("gcc@12.1.0")
captured = capsys.readouterr()

assert (
"gcc@12.1.0 is already an available compiler"
in captured.out
)
assert "gcc@12.1.0 is already an available compiler" in captured.out
except RunnerError as e:
pytest.skip("%s" % e)


def test_external_env_copies(tmpdir):
def test_external_env_copies(tmpdir, request):
src_spack_yaml = """
spack:
specs: [ 'zlib' ]
Expand Down Expand Up @@ -434,13 +420,13 @@ def test_external_env_copies(tmpdir):

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

with open(os.path.join(generated_env, "spack.yaml"), "r") as f:
with open(os.path.join(generated_env, "spack.yaml")) as f:
assert "zlib" in f.read()
except RunnerError as e:
pytest.skip("%s" % e)


def test_configs_apply_to_external_env(tmpdir):
def test_configs_apply_to_external_env(tmpdir, request):
src_spack_yaml = """
spack:
specs: [ 'zlib' ]
Expand All @@ -459,7 +445,7 @@ def test_configs_apply_to_external_env(tmpdir):

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

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


def test_invalid_external_env_errors(tmpdir):
def test_invalid_external_env_errors(tmpdir, request):
with tmpdir.as_cwd():
try:
sr = SpackRunner(dry_run=True)
Expand All @@ -487,9 +473,7 @@ def test_invalid_external_env_errors(tmpdir):
("flags", "--scope site", "'--scope', 'site'"),
],
)
def test_config_compiler_find_attribute(
tmpdir, capsys, attr, value, expected_str
):
def test_config_compiler_find_attribute(tmpdir, capsys, attr, value, expected_str, request):

import os

Expand Down Expand Up @@ -517,12 +501,8 @@ def test_config_compiler_find_attribute(
f.write(compilers_config)

config_path = os.getcwd()
with ramble.config.override(
"config:spack", {"global": {"flags": f"-C {config_path}"}}
):
with ramble.config.override(
"config:spack", {"compiler_find": {attr: value}}
):
with ramble.config.override("config:spack", {"global": {"flags": f"-C {config_path}"}}):
with ramble.config.override("config:spack", {"compiler_find": {attr: value}}):
try:
sr = SpackRunner(dry_run=True)
sr.create_env(os.getcwd())
Expand All @@ -536,28 +516,24 @@ def test_config_compiler_find_attribute(
pytest.skip("%s" % e)


def test_env_create_no_view(tmpdir):
def test_env_create_no_view(tmpdir, request):

import os

with tmpdir.as_cwd():
with ramble.config.override(
"config:spack", {"env_create": {"flags": "--without-view"}}
):
with ramble.config.override("config:spack", {"env_create": {"flags": "--without-view"}}):
try:
sr = SpackRunner()
sr.create_env(os.getcwd())

assert not os.path.exists(
os.path.join(os.getcwd(), ".spack-env", "view")
)
assert not os.path.exists(os.path.join(os.getcwd(), ".spack-env", "view"))
except RunnerError as e:
pytest.skip("%s" % e)


def test_multiword_args(tmpdir, capsys):
def test_multiword_args(tmpdir, capsys, request):
try:
env_path = tmpdir.join("spack-env")
env_path = tmpdir.join(request.node.name)
with ramble.config.override(
"config:spack",
{"install": {"flags": 'install="-multiword -args"'}},
Expand Down
Loading