473,394 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1459
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Will Stuyvesant | last post by:
I have a unittest testfile like this: ----------------------- test_mod.py --------------------- import sys sys.path.append('..') import unittest import mod class...
12
by: Paul Moore | last post by:
One of the things I really dislike about Unittest (compared, say, to a number of adhoc testing tricks I've used in the past, and to Perl's "standard" testing framework) is that the...
0
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally...
7
by: Jorgen Grahn | last post by:
I have a set of tests in different modules: test_foo.py, test_bar.py and so on. All of these use the simplest possible internal layout: a number of classes containing test*() methods, and the good...
0
by: ajikoe | last post by:
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
3
by: David Vincent | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hello I'm hoping to get some insight into a situation that seems odd to me. My Python experience is limited; I've just started using the unittest module....
2
by: Oleg Paraschenko | last post by:
Hello, I decided to re-use functionality of "unittest" module for my purposes. More precisely, I have a list of folders. For each folder, code should enter to the folder, execute a command and...
0
by: Chris Fonnesbeck | last post by:
I have built the following unit test, observing the examples laid out in the python docs: class testMCMC(unittest.TestCase): def setUp(self): # Create an instance of the sampler...
3
by: Paul Moore | last post by:
My normal testing consists of a tests.py script using unittest, with the basic if __name__ == '__main__': unittest.main() incantation to get things going. But I now want to incorporate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.