471,055 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,055 software developers and data experts.

unittest can not use function name 'test' ?

Hello

I found something strange in my unittest :
This code is ok (will report error ):

class MyTest1(unittest.TestCase):

def runTest(self):
self.assertEqual(2,3)
pass

if __name__ == '__main__':
unittest.main()
But if I add a function with the first name is 'test' it fails to
recognize the error:
class MyTest1(unittest.TestCase):
def test1(self):
pass

def runTest(self):
self.assertEqual(2,3)
pass

if __name__ == '__main__':
unittest.main()
Please help
pujo

Nov 22 '05 #1
4 1345
aj****@gmail.com wrote:
I found something strange in my unittest :
This code is ok (will report error ):

class MyTest1(unittest.TestCase):

def runTest(self):
self.assertEqual(2,3)
pass

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

But if I add a function with the first name is 'test' it fails to
recognize the error:

class MyTest1(unittest.TestCase):
def test1(self):
pass

def runTest(self):
self.assertEqual(2,3)
pass

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


the runTest() method is a fallback, and is only used if you don't have any
test*() methods in your test case. see e.g.

http://docs.python.org/lib/organizing-tests.html

</F>

Nov 22 '05 #2
aj****@gmail.com wrote:
I found something strange in my unittest :
This code is ok (will report error ):

class MyTest1(unittest.TestCase):

def runTest(self):
self.assertEqual(2,3)
pass

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

But if I add a function with the first name is 'test' it fails to
recognize the error:

class MyTest1(unittest.TestCase):
def test1(self):
pass

def runTest(self):
self.assertEqual(2,3)
pass

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


the runTest() method is a fallback, and is only used if you don't have any
test*() methods in your test case. see e.g.

http://docs.python.org/lib/organizing-tests.html

</F>

Nov 22 '05 #3
Thanks Fredrik...

pujo

Nov 22 '05 #4
Thanks Fredrik...

pujo

Nov 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Will Stuyvesant | last post: by
12 posts views Thread by Paul Moore | last post: by
reply views Thread by Remy Blank | last post: by
7 posts views Thread by Jorgen Grahn | last post: by
reply views Thread by ajikoe | last post: by
3 posts views Thread by David Vincent | last post: by
2 posts views Thread by Oleg Paraschenko | last post: by
reply views Thread by Chris Fonnesbeck | last post: by
3 posts views Thread by Paul Moore | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.