Skip to content

Commit a22cfc6

Browse files
committed
fixup test_environment: improve error reporting
1 parent 19a0c37 commit a22cfc6

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tests/test_environment.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def assert_env_matches(
6262
if not env_accepts_null():
6363
e.pop("LC_CTYPE", None)
6464
e.pop("__CF_USER_TEXT_ENCODING", None)
65-
assert len(e) == 0, f"Unexpected environment variable(s): {', '.join(e.keys())}"
65+
assert (
66+
len(e) == 0
67+
), f"Unexpected environment variable(s): {', '.join(e.keys())} from env {env}."
6668

6769

6870
class CheckHolder(ABC):
@@ -122,6 +124,10 @@ def HOME(v: str, env: Env) -> bool:
122124
class Singularity(CheckHolder):
123125
"""Run in a Singularity container."""
124126

127+
@staticmethod
128+
def get_sing_version() -> Version:
129+
return Version(".".join(map(str, get_version()[0])))
130+
125131
@staticmethod
126132
def checks(tmp_prefix: str) -> EnvChecks:
127133
"""Create checks."""
@@ -139,7 +145,7 @@ def PWD(v: str, env: Env) -> bool:
139145
}
140146

141147
# Singularity variables appear to be in flux somewhat.
142-
version = Version(".".join(map(str, get_version()[0])))
148+
version = Singularity.get_sing_version()
143149
assert version >= Version("3"), "Tests only work for Singularity 3+"
144150
sing_vars: EnvChecks = {
145151
"SINGULARITY_CONTAINER": None,
@@ -308,9 +314,15 @@ def test_preserve_all(
308314

309315
for vname, val in env.items():
310316
try:
317+
assert vname in checks, env
311318
assert_envvar_matches(checks[vname], vname, env)
312319
except KeyError as kerr:
313320
if vname not in os.environ:
321+
if crt_params_ == Singularity:
322+
print(
323+
f"Raw Singularity version: {get_version()}, "
324+
"processed version: {Singularity.get_sing_version()}."
325+
)
314326
raise kerr
315327
assert val == os.environ[vname]
316328
except AssertionError:

tests/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def get_tool_env(
156156

157157
with working_directory(tmp_path):
158158
rc, stdout, stderr = get_main_output(
159-
args,
159+
["--debug"] + args,
160160
replacement_env=replacement_env,
161161
extra_env=extra_env,
162162
monkeypatch=monkeypatch,

0 commit comments

Comments
 (0)