title: How to sort unittest TestCases properly?
body: <p>For instance, I want these to run in the order they appear in the file.</p>
  
  <pre><code>import unittest
  
  class Test_MyTests(unittest.TestCase):
  
      def test_run_me_first(self): pass
      def test_2nd_run_me(self):   pass
      def test_and_me_last(self):  pass
  
  class Test_AnotherClass(unittest.TestCase):
  
      def test_first(self):        pass
      def test_after_first(self):  pass
      def test_de_last_ding(self): pass
  
  if __name__ == "__main__":
      unittest.main(verbosity=2)
  </code></pre>
  
  <p>Running this gives</p>
  
  <pre><code>test_after_first (__main__.Test_AnotherClass) ... ok
  test_de_last_ding (__main__.Test_AnotherClass) ... ok
  test_first (__main__.Test_AnotherClass) ... ok
  test_2nd_run_me (__main__.Test_MyTests) ... ok
  test_and_me_last (__main__.Test_MyTests) ... ok
  test_run_me_first (__main__.Test_MyTests) ... ok
  </code></pre>
  
  <p>Not what I want.</p>
  
  <p>The answers I've found here on SO after searching all either dance around and avoid the issue by calling / grouping tests or saying</p>
  
  <ul>
  <li><p>"don't do it, just write your tests differently" or</p></li>
  <li><p>"name your tests lexicographically!"</p></li>
  </ul>
  
  <p>...except for <a href="https://stackoverflow.com/a/18499093/4532996">one</a>, which does what I want:</p>
  
  <pre><code>loader = unittest.TestLoader()
  ln = lambda f: getattr(MyTestCase, f).im_func.func_code.co_firstlineno
  lncmp = lambda a, b: cmp(ln(a), ln(b))
  loader.sortTestMethodsUsing = lncmp
  unittest.main(testLoader=loader, verbosity=2)
  </code></pre>
  
  <p>but only for one TestCase class, and only in Python 2. </p>
  
  <p>I want to run all my Python 3 <code>unittest.TestCase</code> subclasses, and I'd like to be able to specify the exact algorithm to use for ordering.</p>
  
  <p>Can I do this in <code>unittest</code>?</p>