Windows XP Python 2.7
I'm following the code in Beginning Python book and have two files in a folder called testing. I'm trying to get it to fail but it wont even run the tests.The first file my_math.py is just a dummy product function
def product(x, y):
pass
The second is the test test_my_math.py
import unittest, my_math
class ProductTestCase(unittest.TestCase):
def testIntegers(self):
for x in xrange(-10, 10):
for y in xrange(-10, 10):
p = my_math.product(x, y)
self.failUnless(p == x*y, 'Integer multiplication failed')
def testFloats(self):
for x in xrange(-10, 10):
for y in xrange(-10, 10):
x = x/10.0
y = y/10.0
p = my_math.product(x, y)
self.failUnless(p == x*y, 'Float multiplicaton failed')
if __name__ == '__main__': unittest.main()
When I run the test in the command line
C:\Python27\Example_Programs\testing>python test_my_math.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
C:\Python27\Example_Programs\testing>
Then unindent that if
to the top level (no spaces before it). Otherwise it is part of the code block of the class
definition and will be executed before the class is finished (thus no unit tests have been created at this point).
The upper reason that Mr. Alfe answered is also correct Other reason might be following
def setUp(self):
self.browser = webdriver.Firefox()
browser=self.browser
browser.get("http://google.com")
It might be possible that you have to probably define this code till browser.get method in setUp() function The rest of the code will be defined in the next segment of the second function
& here setUp() function name is mandatory , otherwise it causes an error
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.