Question

a lot of the standard libraries does not use a class name, how do you run a single test case from command line or add it to the test suite?

similar question asked here but all the solution assume the test case resides in a file with a valid class name.

Running single test from unittest.TestCase via command line

Was it helpful?

Solution

easy way, install nosetest

nosetests -mtestAcosh /home/jamie/Downloads/Python-2.6.5/Lib/test/test_math.py

complicated way, load the test file as a module and then run unittest.main with args

PYTHONPATH=/home/jamie/Downloads/Python-2.6.5/Lib/test python -c'from test_math import MathTests
import unittest
unittest.main(None,None,["","test_math.MathTests.testAcosh"])
'

The version of test_math.py I happen to have does not have unittest.main() in it The usual way to write simple unittest files is to add

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

when this is how the unittest files are set up then running individual tests can usually be done as described in this answer

Running single test from unittest.TestCase via command line

ie, just give "testClassName.test_iwanttorun" as a command line arg

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top