unittest can not use function name 'test' ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ajikoe@gmail.com

    #1

    unittest can not use function name 'test' ?

    Hello

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

    class MyTest1(unittes t.TestCase):

    def runTest(self):
    self.assertEqua l(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(unittes t.TestCase):
    def test1(self):
    pass

    def runTest(self):
    self.assertEqua l(2,3)
    pass

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


    Please help
    pujo

  • Fredrik Lundh

    #2
    Re: unittest can not use function name 'test' ?

    ajikoe@gmail.co m wrote:
    [color=blue]
    > I found something strange in my unittest :
    > This code is ok (will report error ):
    >
    > class MyTest1(unittes t.TestCase):
    >
    > def runTest(self):
    > self.assertEqua l(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(unittes t.TestCase):
    > def test1(self):
    > pass
    >
    > def runTest(self):
    > self.assertEqua l(2,3)
    > pass
    >
    > if __name__ == '__main__':
    > unittest.main()[/color]

    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.



    </F>



    Comment

    • Fredrik Lundh

      #3
      Re: unittest can not use function name 'test' ?

      ajikoe@gmail.co m wrote:
      [color=blue]
      > I found something strange in my unittest :
      > This code is ok (will report error ):
      >
      > class MyTest1(unittes t.TestCase):
      >
      > def runTest(self):
      > self.assertEqua l(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(unittes t.TestCase):
      > def test1(self):
      > pass
      >
      > def runTest(self):
      > self.assertEqua l(2,3)
      > pass
      >
      > if __name__ == '__main__':
      > unittest.main()[/color]

      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.



      </F>



      Comment

      • ajikoe@gmail.com

        #4
        Re: unittest can not use function name 'test' ?

        Thanks Fredrik...

        pujo

        Comment

        • ajikoe@gmail.com

          #5
          Re: unittest can not use function name 'test' ?

          Thanks Fredrik...

          pujo

          Comment

          Working...