title: How to use setUp and tearDown in python unittest for this class
body: <p>I am having an hard time learning test driven development.</p>
  
  <p>I am writing a class which would take either a filename or file description and size an input and return the size-chunk of data from the file.</p>
  
  <p>While starting out with the tests first all I could come up was to test if the arguments passed were not none and to check if arguments are valid fileobjects.</p>
  
  <p>All i could muster up was below code, am I use the setUp and tearDown methods as I should or it is completely wrong? I am creating a temporary file and instance of class defined to read in the setUp() and am I supposed to remove the object someway in tearDown()</p>
  
  <p>Below is the code</p>
  
  <pre><code>class Test_FileChunk(unittest.TestCase):
      """
      """
      def setUp(self):
          self.fhandle, self.fname = mkstemp()
          self.fc_obj = FileChunk(filename=self.fname)
  
      def tearDown(self):
          try:
              os.remove(self.fname)
          except OSError as oserr:
              print(oserr)
  
      def test_instance_variables(self):
          self.assertIsNotNone(self.fc_obj.filename)
          self.assertIsNone(self.fc_obj.filehandle)
          self.assertEqual(self.fc_obj.chunk_size, 8192)
  
      def test_check_if_instance_variables_are_valid_file_objects(self):
          handle = open(self.fc_obj.filename
          self.assertEqual(
              hasattr
                  (handle, "r"), 'seek'), True,
                      msg="Is not a valid file object")
          handle.close()
  </code></pre>
  
  <p>I went through multiple TDD questions on stackoverflow and suggested tutorials but still it seems following a TDD tutorial is very interesting but actually doing TDD is very difficult. I can actually think of what I want to do in ReadChunk class but just cannot get my head around actually find the tests first and then writing the code. I was able to think to check whether the passed values are valid file object through TDD which wouldn't have occurred if I were coding without TDD, but I am not sure if I am using the unittest correctly. Cannot get the big picture. Could anyone please suggest how to go about this and whether the above code snipped is correct.</p>