[Python-Dev] "if __name__ == '__main__'" at the bottom of python unittest files

Chris Withers chris at withers.org
Wed May 1 08:30:40 EDT 2019


On 01/05/2019 13:21, Victor Stinner wrote:
> Le mer. 1 mai 2019 à 03:12, Chris Withers <chris at withers.org> a écrit :
>> Right, but that's not the documented way of running individual suites in
>> the devguide.
> 
> Maybe, but I'm using that sometimes and it's useful for some specific
> issues. Is it possible to run an individual test file using unittest?
> 
> Something like ./python -m unittest
> Lib/unittest/test/testmock/testcallable.py -v

Yep:

$ ./python.exe -m unittest Lib/unittest/test/testmock/testsentinel.py
......
----------------------------------------------------------------------
Ran 6 tests in 0.002s

$ ./python.exe -m unittest -v Lib/unittest/test/testmock/testsentinel.py
testBases (Lib.unittest.test.testmock.testsentinel.SentinelTest) ... ok
testCopy (Lib.unittest.test.testmock.testsentinel.SentinelTest) ... ok
testDEFAULT (Lib.unittest.test.testmock.testsentinel.SentinelTest) ... ok
testPickle (Lib.unittest.test.testmock.testsentinel.SentinelTest) ... ok
testSentinelName (Lib.unittest.test.testmock.testsentinel.SentinelTest) 
... ok
testSentinels (Lib.unittest.test.testmock.testsentinel.SentinelTest) ... ok

----------------------------------------------------------------------
Ran 6 tests in 0.003s

OK

$ ./python.exe -m unittest -v unittest.test.testmock.testsentinel
testBases (unittest.test.testmock.testsentinel.SentinelTest) ... ok
testCopy (unittest.test.testmock.testsentinel.SentinelTest) ... ok
testDEFAULT (unittest.test.testmock.testsentinel.SentinelTest) ... ok
testPickle (unittest.test.testmock.testsentinel.SentinelTest) ... ok
testSentinelName (unittest.test.testmock.testsentinel.SentinelTest) ... ok
testSentinels (unittest.test.testmock.testsentinel.SentinelTest) ... ok

----------------------------------------------------------------------
Ran 6 tests in 0.003s

cheers,

Chris


More information about the Python-Dev mailing list