Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: test_sandbox tests didn't close dockers (#2274)

tobitege1fa09e04148b
diff --git a/tests/unit/test_sandbox.py b/tests/unit/test_sandbox.py
index c12fa2c067..9bd8653549 100644
--- a/tests/unit/test_sandbox.py
+++ b/tests/unit/test_sandbox.py
@@ -127,6 +127,7 @@ def test_ssh_box_run_as_devin(temp_dir):
exit_code, output = box.execute('ls -l test')
assert exit_code == 0, 'The exit code should be 0.'
assert 'foo.txt' in output, 'The output should contain the foo.txt file'
+ box.close()
def test_ssh_box_multi_line_cmd_run_as_devin(temp_dir):
@@ -147,6 +148,7 @@ def test_ssh_box_multi_line_cmd_run_as_devin(temp_dir):
'The output should be the same as the input for '
+ box.__class__.__name__
)
+ box.close()
def test_ssh_box_stateful_cmd_run_as_devin(temp_dir):
@@ -178,6 +180,7 @@ def test_ssh_box_stateful_cmd_run_as_devin(temp_dir):
assert output.strip() == '/workspace/test', (
'The output should be /workspace for ' + box.__class__.__name__
)
+ box.close()
def test_ssh_box_failed_cmd_run_as_devin(temp_dir):
@@ -193,6 +196,7 @@ def test_ssh_box_failed_cmd_run_as_devin(temp_dir):
'The exit code should not be 0 for a failed command for '
+ box.__class__.__name__
)
+ box.close()
def test_single_multiline_command(temp_dir):
@@ -217,6 +221,7 @@ def test_single_multiline_command(temp_dir):
'The output should be the same as the input for '
+ box.__class__.__name__
)
+ box.close()
def test_multiline_echo(temp_dir):
@@ -241,6 +246,7 @@ def test_multiline_echo(temp_dir):
'The output should be the same as the input for '
+ box.__class__.__name__
)
+ box.close()
def test_sandbox_whitespace(temp_dir):
@@ -251,7 +257,6 @@ def test_sandbox_whitespace(temp_dir):
config, 'sandbox_type', new='ssh'
):
for box in [DockerSSHBox(), DockerExecBox()]:
- # test the ssh box
exit_code, output = box.execute('echo -e "\\n\\n\\n"')
assert exit_code == 0, (
'The exit code should be 0 for ' + box.__class__.__name__
@@ -266,6 +271,7 @@ def test_sandbox_whitespace(temp_dir):
'The output should be the same as the input for '
+ box.__class__.__name__
)
+ box.close()
def test_sandbox_jupyter_plugin(temp_dir):
@@ -277,8 +283,6 @@ def test_sandbox_jupyter_plugin(temp_dir):
):
for box in [DockerSSHBox()]:
box.init_plugins([JupyterRequirement])
-
- # test the ssh box
exit_code, output = box.execute('echo "print(1)" | execute_cli')
print(output)
assert exit_code == 0, (
@@ -288,3 +292,4 @@ def test_sandbox_jupyter_plugin(temp_dir):
'The output should be the same as the input for '
+ box.__class__.__name__
)
+ box.close()