title: How to properly use self.assertRaisesRegex as a context manager?
body: <p>Please check the below code:</p>
  
  <pre><code>import unittest
  
  
  def fn():
      raise KeyError('my message')
  
  
  class Test(unittest.TestCase):
      def test_passes(self):
          with self.assertRaisesRegex(KeyError, 'my message'):
              fn()
  
          with self.assertRaisesRegex(KeyError, 'my'):
              fn()
  
      def test_fails(self):
          # Why does this test fail?
          # Isn't '^my message$' a valid regex?
          # How do I check if the message is exactly 'my message'?
          with self.assertRaisesRegex(KeyError, '^my message$'):
              fn()
  
  
  unittest.main()
  </code></pre>
  
  <p>In the output, I get the below message for the test <code>test_fails</code>:</p>
  
  <blockquote>
    <p>AssertionError: "^my message$" does not match "'my message'"</p>
  </blockquote>
  
  <hr>
  
  <p><strong>What am I missing?</strong></p>
  
  <hr>
  
  <p>As mentioned in the comments, these are my questions:</p>
  
  <ul>
  <li>Why does this test fail?</li>
  <li>Isn't <code>'^my message$'</code> a valid regex?</li>
  <li>How do I check if the message is <code>exactly 'my message'</code>?</li>
  </ul>