0
class TestVehicle(TestCase):

    def test_speed(self):
        #checks for speed

    def test_fuel(self):
        #checks fuel quantity

I have the above test class with two test methods, but while testing I want to run only one of the two methods. How can I achieve this using

unittest.defaultTestLoader.loadTestsFromName()
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Arijit
  • 175
  • 1
  • 5
  • 3
    Possible duplicate of [Running single test from unittest.TestCase via command line](http://stackoverflow.com/questions/15971735/running-single-test-from-unittest-testcase-via-command-line) –  Jun 01 '16 at 08:49
  • @Lutz I am not trying to achieve this from command line ,I have a helper class where I create the test suit and execute using unittest.TextTestRunner – Arijit Jun 01 '16 at 08:58

1 Answers1

0

You can give the function name too:

unittest.defaultTestLoader.loadTestsFromName('TestVehicle.test_speed')

This would only run the test_speed test.

noteness
  • 2,440
  • 1
  • 15
  • 15