code: def test_collect_granular_priority_on_collision(
      tmp_dir, dvc, run_copy
  ):
      tmp_dir.gen({"dir": {"foo": "foo"}, "foo": "foo"})
      (stage1,) = dvc.add("dir/*", glob=True)
      stage2 = run_copy("foo", "bar", name="dir")
  
      assert dvc.stage.collect_granular("dir") == [(stage2, None)]
      assert dvc.stage.collect_granular("dir", recursive=True) == [
          (stage1, None)
      ]
  
      remove(tmp_dir / "dir")
  
      assert dvc.stage.collect_granular("dir") == [(stage2, None)]
      assert dvc.stage.collect_granular("dir", recursive=True) == [
          (stage2, None)
      ]
  
imports: import os
  from operator import itemgetter
  import pytest
  from funcy import raiser
  from dvc.dvcfile import PROJECT_FILE, FileIsGitIgnored
  from dvc.exceptions import NoOutputOrStageError
  from dvc.repo import Repo
  from dvc.stage.exceptions import StageFileDoesNotExistError, StageNameUnspecified, StageNotFound
  from dvc.utils import relpath
  from dvc.utils.fs import remove
  from dvc.utils.strictyaml import YAMLValidationError
label_desc: Use image node_id 15 for calling a global function with example usage: test_collect_granular_priority_on_collision(tmp_dir, dvc, run_copy) without return types