From: John Maclean on 10 May 2010 08:38 hi, can some one explain why the __first__ test is not being run? #!/usr/bin/env python import unittest # {{{ class T1TestCase(unittest.TestCase): def setUp(self): pass # can we use global variables here? def tearDown(self): pass # garbage collection def test_T1(self): '''this test aint loading''' self.assertEquals(1, 0) def test_T2(self): ## test method names begin 'test*' self.assertEquals((1 + 2), 3) self.assertEquals(0 + 1, 1) def test_T3(self): self.assertEquals((0 * 10), 0) self.assertEquals((5 * 8), 40) # the output is better. prints each test and ok or fail suite = unittest.TestLoader().loadTestsFromTestCase(T1TestCase) unittest.TextTestRunner(verbosity=2).run(suite) # }}} ''' halp! the first test ain't loading... python blaht.py test_T2 (__main__.T1TestCase) ... ok test_T3 (__main__.T1TestCase) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.000s OK '''
From: Joe Riopel on 10 May 2010 08:44 On Mon, May 10, 2010 at 8:38 AM, John Maclean <jayeola(a)gmail.com> wrote: > hi, > > can some one explain why the __first__ test is not being run? It looks like you defined test_T1 inside of the tearDown method.
From: J. Cliff Dyer on 10 May 2010 09:38 My guess is you mixed tabs and spaces. One tab is always treated by the python interpreter as being equal to eight spaces, which is two indentation levels in your code. Though if it were exactly as you show it, you'd be getting a syntax error, because even there, it looks like the indentation of your `def test_T1(self):` line is off by one column, relative to pass, and by three columns relative to the other methods. Cheers, Cliff On Mon, 2010-05-10 at 13:38 +0100, John Maclean wrote: > hi, > > can some one explain why the __first__ test is not being run? > > #!/usr/bin/env python > import unittest # {{{ > class T1TestCase(unittest.TestCase): > > def setUp(self): > pass # can we use global variables here? > > def tearDown(self): > pass # garbage collection > > def test_T1(self): > '''this test aint loading''' > self.assertEquals(1, 0) > > def test_T2(self): ## test method names begin 'test*' > self.assertEquals((1 + 2), 3) > self.assertEquals(0 + 1, 1) > > def test_T3(self): > self.assertEquals((0 * 10), 0) > self.assertEquals((5 * 8), 40) > > # the output is better. prints each test and ok or fail > suite = unittest.TestLoader().loadTestsFromTestCase(T1TestCase) > unittest.TextTestRunner(verbosity=2).run(suite) # }}} > > > ''' halp! > > the first test ain't loading... > > python blaht.py > test_T2 (__main__.T1TestCase) ... ok > test_T3 (__main__.T1TestCase) ... ok > > ---------------------------------------------------------------------- > Ran 2 tests in 0.000s > > OK > > '''
From: John Maclean on 10 May 2010 10:21 On 10/05/2010 14:38, J. Cliff Dyer wrote: > My guess is you mixed tabs and spaces. One tab is always treated by the > python interpreter as being equal to eight spaces, which is two > indentation levels in your code. > > Though if it were exactly as you show it, you'd be getting a syntax > error, because even there, it looks like the indentation of your `def > test_T1(self):` line is off by one column, relative to pass, and by > three columns relative to the other methods. > > Cheers, > Cliff 'twas a spaces/indent issue. thanks!
From: cjw on 10 May 2010 17:17 On 10-May-10 10:21 AM, John Maclean wrote: > On 10/05/2010 14:38, J. Cliff Dyer wrote: >> My guess is you mixed tabs and spaces. One tab is always treated by the >> python interpreter as being equal to eight spaces, which is two >> indentation levels in your code. >> >> Though if it were exactly as you show it, you'd be getting a syntax >> error, because even there, it looks like the indentation of your `def >> test_T1(self):` line is off by one column, relative to pass, and by >> three columns relative to the other methods. >> >> Cheers, >> Cliff > > 'twas a spaces/indent issue. thanks! > > > PyScripter and PythonWin permit the user to choose the equivalence of tabs and spaces. I like two spaces = on tab, it's a matter of taste. I feel that eight spaces is too much. Colin W.
|
Next
|
Last
Pages: 1 2 Prev: Is Python a functional programming language? Next: Upgrade Python 2.6.4 to 2.6.5 |