title: how to add tests dynamically to python unittest
body: <p>I'm wanting to set up a <code>unittest</code> TestCase where some of the cases are added dynamically. The methods are added as shown from my <code>test_nothing</code>, but, <code>unittest</code> doesn't take them into account as it runs only one test.  It's like I build my <code>test_xxxx</code> too late and they are not seen. Is <code>setUpClass</code> executed too late in the game? Should I put this in <code>__init__</code> build my methods, and then call <code>super().__init__</code> ?</p>
  <pre><code>import unittest
  import blognodes
  
  class Test_base62(unittest.TestCase):
    testset = { 0: '0', 10: 'a', 61: 'Z', 62: '10', 3844: '100'}
  
    @classmethod
    def setUpClass(cls):
      cls.testme = 5
      print(&quot;i am the setUp function&quot;)
      for d, b62 in cls.testset.items():
        print(&quot;building the first set&quot;)
        cls.build_test_base62_values(d, b62)
        print(&quot;building the second set&quot;)
        cls.build_test_int_values(d, b62)
  
  
    @classmethod
    def build_test_base62_values(cls, d, b62):
      def f(cls):
        target = blognodes.base62(d)
        cls.assertEqual(target.str(), b62)
      fname = &quot;test_base62_value_{}&quot;.format(d)
      setattr(cls, fname, f)
  
    @classmethod
    def build_test_int_values(cls, d, b62):
      def f(cls):
        target = blognodes.base62(d)
        cls.assertEqual(target.int(), d)
      fname = &quot;test_int_value_{}&quot;.format(d)
      setattr(cls, fname, f)
  
    def test_nothing(self):
      print(&quot;i'm test nothing&quot;)
      t = dir(self)
      print(t)
      self.assertEqual(5, self.testme)
  </code></pre>
  <p>Thanks.</p>