Ver código fonte

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

* fix test_sandbox tests to close dockers

* removed try/finally

---------

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
tobitege 1 ano atrás
pai
commit
1fa09e0414
1 arquivos alterados com 8 adições e 3 exclusões
  1. 8 3
      tests/unit/test_sandbox.py

+ 8 - 3
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()