title: Python Regexs Unit Testing
body: <p>I am trying to do some unit testing on a little regex def. </p>
  
  <pre><code>x = "TEST TEST TEST. Regular Expressions. TEST TEST TEST"
  
  def find_start_end(phrase,sample_set):
      m = re.search(phrase, sample_set)
  
      start = m.start()
      end = m.end()
      return (start,end)
      #print(start,end)
  
  if __name__ =="__main__":
      print(find_start_end("Regular Expressions", x))
  </code></pre>
  
  <p>This returns (16,35)....</p>
  
  <p>My testing Unit is.... </p>
  
  <pre><code>import unittest
  
  class TestAlpha(unittest.TestCase):
  
  
  def test_1(self):
      x = "Regular Expressions"
      self.assertEqual((0, 19), find_start_end("Regular Expressions", x))
  
  def test_2(self):
          x = "TEST TEST TEST. Regular Expression. TEST TEST TEST"
          self.assertRaises(AttributeError, find_start_end("Regular Expressions", x))
  
  if __name__ == "__main__":
      unittest.main()
  </code></pre>
  
  <p>Test 1 passes fine, my question is on test_2 how do I test for the <code>AttributeError: 'NoneType' object has no attribute 'start'</code>.</p>
  
  <p>I was trying to use <code>assertRaises</code>, but I am not sure what I am doing wrong. I am open to any suggestions that would work better. Just trying to figure out how to test for the <code>NoneType</code>. I am very new to regular expressions.</p>