title: How to mock python build in methods
body: <p>I have a python method does the following:</p>
  
  <ol>
  <li>list the files under a directory using os.listdir(/test)</li>
  <li>regex match some of the files under the directory, put the files in a list</li>
  <li>read the contents out of files in the list, do some aggregation stuff.</li>
  </ol>
  
  <p>Obviously, the only interesting part for me to test in my case is 2, 3, so 1 is definitely something I want to mock against. I started doing patch file creation/deletion under /test folder in my setUp() and tearDown(). But colleague told me it's not good idea to do I/O in unitest. </p>
  
  <p>so what's the best way to mock build in os.listdir() in my unitest? or what's the alternatives?</p>
  
  <p>Is there anything I can do to achieve something like:</p>
  
  <pre><code>setUp() {
      #mock a few files eg.test1.txt, test2.txt, test3.txt under directory /test 
      #without physically creating them using I/O
  }
  tearDown() {
     #whatever cleanup required 
  }
  </code></pre>