code: def mock_filesystem():
      """Create a mock filesystem, patching `open` and `os.path.isfile`."""
  
      class FakeFile:
          """Fake file based on BytesIO."""
  
          def __init__(self):
              self.io = io.BytesIO()
  
          def __enter__(self):
              return self.io
  
          def __exit__(self, *args, **kwargs):
              self.io.seek(0)
  
      fake_fs = defaultdict(FakeFile)
      mo = mock.mock_open()
  
      def fun(filename, *args, **kwargs):
          return fake_fs[filename]
  
      mo.side_effect = fun
      with mock.patch("builtins.open", mo):
          with mock.patch("os.path.isfile") as isfile:
              isfile.side_effect = lambda target: target in fake_fs
              yield
  
imports: from __future__ import annotations
  import contextlib
  import io
  import os
  import sys
  import tarfile
  import unittest
  from collections import defaultdict
  from unittest import mock
  import pytest
label_desc: Use image node_id 3 for calling a global function with example usage: mock_filesystem() and returns: fake_fs, self