title: What is a good way to open configs or files during unit test in python?
body: <p>I am wondering what is a good way to read config or local file during the unit testing.</p>
  
  <p>I think it could be either to write the test config file during time. For example:</p>
  
  <pre><code>def setUp(self):
      self.config = ConfigParser.RawConfigParser()
      self.config.add_section('TestingSection')
      self.config.set('TestingSection', 'x', '1')
  
      with open('local_file.txt', 'w') as f:
          f.write('testing_value')
  </code></pre>
  
  <p>or files could be prepared before testing, and we just open them during testing, for example:</p>
  
  <pre><code>def setUp(self):
      self.config = ConfigParser.RawConfigParser()
      self.config('local_config_file_path')
  
      with open('local_file.txt', 'r') as f:
          self.testing_value = f.read()
  </code></pre>
  
  <p>I am not sure which is the better way to read files during the unit testing, and hope some experts can help me.</p>
  
  <p>If you have better approach of it, please share with me.</p>
  
  <p>Thank you.</p>