code: def fx_cache_dir(request: SubRequest) -> Generator[None, None, None]:
      """Add a `cache_dir` attribute pointing to a temporary directory in tests.
  
      Example:
      ```py
      @pytest.mark.usefixtures("fx_cache_dir")
      class TestWithCache(unittest.TestCase):
          cache_dir: Path
  
          def test_cache_dir(self) -> None:
              self.assertTrue(self.cache_dir.is_dir())
      ```
      """
      with SoftTemporaryDirectory() as cache_dir:
          request.cls.cache_dir = Path(cache_dir).resolve()
          yield
          # TemporaryDirectory is not super robust on Windows when a git repository is
          # cloned in it. See https://www.scivision.dev/python-tempfile-permission-error-windows/.
          shutil.rmtree(
              cache_dir, onerror=set_write_permission_and_retry
          )
  
file_path: huggingface_hub/tests/conftest.py
imports: import os
  import shutil
  from pathlib import Path
  from typing import Generator
  import pytest
  from _pytest.fixtures import SubRequest
  import huggingface_hub
  from huggingface_hub.utils import SoftTemporaryDirectory, logging
  from .testing_utils import set_write_permission_and_retry
label_desc: Use image node_id 1 for calling a global function with example usage: fx_cache_dir(request) without return types