title: mocking a directory subtree for pytest
body: <p>I have recursive code to gather tests from given directory. It relies on few functions: isdir, isfile, and acess to files. It expects that directories can be listed with os.listdir.</p>
  
  <p>To test this function I need to mock a lot of functions in very non-trivial way. Is any way to mock all os/os.path related thing in short way with given filelist? Something like "<code>mock_subdir(example_in_tar_gz):</code>" or with some kind of DSL to describe mocked directory tree structure.</p>
  
  <p>Function of interest:</p>
  
  <pre><code>def gather_tests(path):
      if os.path.isdir(path):
          filelist = [os.path.join(path, f) for f in os.listdir(path)]
          filelist.sort()
          all_files = map(gather_tests, filelist)
          return filter(None, all_files)
      elif os.path.isfile(path) and os.access(path, os.X_OK):
          return path
      else:
          return None
  </code></pre>
  
  <p>Thanks.</p>