title: Python unit testing: change exit code
body: <p>I'm using the <a href="https://docs.python.org/3/library/unittest.html" rel="nofollow noreferrer">unittest</a> framework and am making a Python script which should imitate the <a href="https://en.wikipedia.org/wiki/Nagios" rel="nofollow noreferrer">Nagios</a> script behavior. So I need it to have exit status 0 when all test passed. And 2 (meaning critical) in case one of the tests fails.</p>
  <p>The code is similar to the example code in the documentation:</p>
  <pre><code>import unittest
  
  class TestStringMethods(unittest.TestCase):
  
  def test_upper(self):
      self.assertEqual('foo'.upper(), 'FOO')
  
  def test_isupper(self):
      self.assertTrue('FOO'.isupper())
      self.assertFalse('Foo'.isupper())
  
  def test_split(self):
      s = 'hello world'
      self.assertEqual(s.split(), ['hello', 'world'])
      # Check that s.split fails when the separator is not a string
      with self.assertRaises(TypeError):
          s.split(2)
  
  if __name__ == '__main__':
     unittest.main()
  </code></pre>
  <p>Here it writes OK and outputs 0 as exit code. And FAILED (failures=..) and 1 as the exit code.</p>
  <p>I would like to place my own string in the output in both these two cases and return 2 in case of failure as the exit code. What should I add here?</p>