code: def test_stage_dump_when_already_exists(tmp_dir, dvc):
      data = {"s1": {"cmd": "command", "deps": [], "outs": []}}
      (tmp_dir / "path.lock").dump({"schema": "2.0", "stages": data})
      stage = PipelineStage(
          name="s2", repo=dvc, path="path", cmd="command2"
      )
      lockfile = Lockfile(dvc, "path.lock")
      lockfile.dump(stage)
      assert lockfile.load() == {
          "schema": "2.0",
          "stages": {**data, "s2": {"cmd": "command2"}},
      }
  
file_path: dvc/tests/unit/test_lockfile.py
imports: import pytest
  from dvc.dvcfile import FileIsGitIgnored, Lockfile
  from dvc.stage import PipelineStage
  from dvc.utils.strictyaml import YAMLValidationError
label_desc: Use image node_id 2 for calling a global function with example usage: test_stage_dump_when_already_exists(tmp_dir, dvc) without return types