code: def test_dump_post_clean_on_error(
      output_already_exists,
      output_specified,
      overwrite,
      error_message,
      capsys,
      tmp_path,
  ):
      """Test how dumped file is cleaned if dump fails."""
  
      # Prepare a command that will fail (by looking for unknown experiment)
      command = ["db", "dump", "-n", "unknown-experiment"]
      if output_specified:
          output_specified = f"{tmp_path}/test.pkl"
          command += ["--output", output_specified]
      if overwrite:
          command += ["--force"]
  
      expected_output = output_specified or "dump.pkl"
  
      # Create expected file if necessary
      output_modified_time = None
      if output_already_exists:
          assert not os.path.exists(expected_output), expected_output
          with open(expected_output, "w"):
              pass
          assert os.path.isfile(expected_output)
          output_modified_time = os.stat(expected_output).st_mtime
  
      # Execute command and expect it to fail
      execute(" ".join(command), assert_code=1)
      err = capsys.readouterr().err
  
      # Check output error
      assert err.startswith(error_message)
  
      # Check dump post-clean
      if output_already_exists:
          # Output should exist after error.
          assert os.path.isfile(expected_output)
          # Output should have not been modified.
          assert (
              output_modified_time == os.stat(expected_output).st_mtime
          )
          # Clean files anyway
          os.unlink(expected_output)
          if os.path.isfile(f"{expected_output}.lock"):
              os.unlink(f"{expected_output}.lock")
      else:
          # Output should not exist after error.
          assert not os.path.exists(expected_output)
          assert not os.path.exists(f"{expected_output}.lock")
  
file_path: orion/tests/functional/commands/test_db_dump.py
imports: import os
  import pytest
  import orion.core.cli
  from orion.core.io.database.pickleddb import PickledDB
  from orion.storage.base import setup_storage
label_desc: Use image node_id 7 for calling a global function with example usage: test_dump_post_clean_on_error(output_already_exists, output_specified, overwrite, error_message, capsys, tmp_path) without return types