1

I have a test_method() in a directory /tests. I want to run a single test from the command line. Instead of using test_module.TestClass.test_method I wish to just mention it as

$ ./test-runner test_method

and let the discover decide the test_method belongs to which test_module and in which TestClass. I am able to get the test_module by running a search based on strings in all test_modules present as test_module is python file. But how to get the TestClass holding the test_method within the file? Any idea?

Sonali Gupta
  • 494
  • 1
  • 5
  • 20

1 Answers1

0

Instead of doing that yourself, you ought to use nose with the nosetests command, or, better, use py-test (and tox).

The classic usage with unit test is to add a main in your module:

if __name__ == "__main__":
    unittest.main()

See the Basic example in the doc

The main function has parameters used to choose the tests to run. See unittest.main in the doc.

Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103