title: Run a specific unit tests in Python from main()
body: <p>I am trying to run only a single test from the unit tests provided in a class. So assuming</p>
  <pre><code>class MytestSuite(unittest.TestCase):
      def test_false(self):
          a = False
          self.assertFalse(a, &quot;Its false&quot;)
  
      def test_true(self):
          a = True
          self.assertTrue(a, &quot;Its true&quot;)
  </code></pre>
  <p>I would like to run only <em>test_false</em>. Based on the Q&amp;A provided on this site and online, I used the following lines of code in my main class</p>
  <pre><code>if __name__ == &quot;__main__&quot;:  # Indentation was wrong
      singletest = unittest.TestSuite()
      singletest.addTest(MytestSuite().test_false)
      unittest.TextTestRunner().run(singletest)
  </code></pre>
  <p>I keep getting errors while trying to add the test. Mainly:</p>
  <blockquote>
  <p>File &quot;C:\Python27\Lib\unittest\case.py&quot;, line 189, in <strong>init</strong> <br />
  (self.<strong>class</strong>, methodName)) <br />
  ValueError: no such test method in &lt;class '<strong>main</strong>.MytestSuite'&gt;: runTest</p>
  </blockquote>
  <p>Do I need a specific runTest method in my class? Is there a way to run particular tests that may belong to different suites? For example, <strong>method A</strong> belonging to <strong>suite class 1</strong> and <strong>method B</strong> belonging to <strong>suite class 2</strong>. Surprisingly this has proven to be a difficult thing to find online. There are multiple examples of doing it through the command line, but not from the program itself.</p>