diff --git a/repo2docker/utils.py b/repo2docker/utils.py index f8bf96c0..bb0d7c2a 100644 --- a/repo2docker/utils.py +++ b/repo2docker/utils.py @@ -50,6 +50,8 @@ def execute_cmd(cmd, capture=False, **kwargs): if c == b"\n": yield flush() c_last = c + if buf: + yield flush() finally: ret = proc.wait() if ret != 0: diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 6b467315..1a106a64 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -27,6 +27,14 @@ def test_capture_cmd_capture_success(): assert line == "test\n" +def test_capture_cmd_noeol_capture_success(): + # This should succeed + lines = list( + utils.execute_cmd(["/bin/bash", "-c", "echo -en 'test\ntest'"], capture=True) + ) + assert lines == ["test\n", "test"] + + def test_capture_cmd_capture_fail(): with pytest.raises(subprocess.CalledProcessError): for line in utils.execute_cmd(