From 6f59fdb20f5083aa1c84bc1ddd81995e5b15cef5 Mon Sep 17 00:00:00 2001 From: Hal Wine Date: Sun, 19 Apr 2020 08:53:01 -0700 Subject: [PATCH] Refactor to eliminate need for volume mount This change allows, imo, the test to be clearer, and should also speed up the test. --- tests/unit/test_env.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/unit/test_env.py b/tests/unit/test_env.py index 70092a28..5d398146 100644 --- a/tests/unit/test_env.py +++ b/tests/unit/test_env.py @@ -16,11 +16,9 @@ def test_env(): with tempfile.TemporaryDirectory() as tmpdir: username = getuser() os.environ["SPAM"] = "eggs" - subprocess.check_call( + result = subprocess.run( [ "repo2docker", - "-v", - "{}:/home/{}".format(tmpdir, username), "-e", "FOO={}".format(ts), "--env", @@ -31,13 +29,18 @@ def test_env(): tmpdir, "/bin/bash", "-c", - "echo -n $FOO > ts && echo -n $BAR > bar && echo -n $SPAM > eggs", - ] + # Docker exports all passed env variables, so we can + # just look at that output + "export", + ], + universal_newlines=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, ) - - with open(os.path.join(tmpdir, "ts")) as f: - assert f.read().strip() == ts - with open(os.path.join(tmpdir, "bar")) as f: - assert f.read().strip() == "baz" - with open(os.path.join(tmpdir, "eggs")) as f: - assert f.read().strip() == "eggs" + assert result.returncode == 0 + # all docker output is returned by repo2docker on stderr + # extract just the declare for better failure message formatting + declares = [x for x in result.stderr.split("\n") if x.startswith("declare")] + assert 'declare -x FOO="{}"'.format(ts) in declares + assert 'declare -x BAR="baz"' in declares + assert 'declare -x SPAM="eggs"' in declares