unittest behaving oddly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Vincent

    #1

    unittest behaving oddly

    -----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. I've had some experience with unit test support in other
    languages.

    Two computers that I use are similarly configured; each has Python 2.3
    installed as distributed with the operating system, as far as I can
    tell. The operating system is Mac OS X 10.3.9 in each case. The
    hardware differs; they are both PowerPC computers. On these machines
    unittest is behaving oddly, both in the same way.

    If I copy the example from the unittest documentation and feed it to
    Python, I get errors about methods in unittest. I think the example is
    intended to pass its tests, but on my machines the code in the example
    is not locating methods from unittest properly.

    I've done some simple things, like inspecting the unittest code in the
    library; it seems to make sense. For instance, the 'assertEquals'
    method is defined as a member of TestCase.

    What could be going wrong? I wonder if I should try to track down
    problems in the example, or in the Python library installation on these
    machines, or somewhere else.

    Below is a transcript illustrating the problem.


    Regards

    David


    PS: transcript illustrating the problem
    [color=blue]
    > Mina:~/Documents/source/unittest-debug dvincent$ cat example.py
    > # unittest example from documentation
    >
    > import unittest
    >
    > class IntegerArithmen ticTestCase(uni ttest.TestCase) :
    > def testAdd(self): ## test method names begin 'test*'
    > assertEquals((1 + 2), 3)
    > assertEquals(0 + 1, 1)
    > def testMultiply(se lf):
    > assertEquals((0 * 10), 0)
    > assertEquals((5 * 8), 40)
    >
    > if __name__ == '__main__':
    > unittest.main()
    >
    > Mina:~/Documents/source/unittest-debug dvincent$ python example.py
    > EE
    > =============== =============== =============== =============== ==========
    > ERROR: testAdd (__main__.Integ erArithmenticTe stCase)
    > ----------------------------------------------------------------------
    > Traceback (most recent call last):
    > File "example.py ", line 7, in testAdd
    > assertEquals((1 + 2), 3)
    > NameError: global name 'assertEquals' is not defined
    >
    > =============== =============== =============== =============== ==========
    > ERROR: testMultiply (__main__.Integ erArithmenticTe stCase)
    > ----------------------------------------------------------------------
    > Traceback (most recent call last):
    > File "example.py ", line 10, in testMultiply
    > assertEquals((0 * 10), 0)
    > NameError: global name 'assertEquals' is not defined
    >
    > ----------------------------------------------------------------------
    > Ran 2 tests in 0.045s
    >
    > FAILED (errors=2)
    > Mina:~/Documents/source/unittest-debug dvincent$ python -V
    > Python 2.3
    > Mina:~/Documents/source/unittest-debug dvincent$[/color]



    - --

    David A Vincent dvincent@toshib a-tap.com
    Software Engineer telephone +61 2 9850-2593
    RESEARCH AND DEVELOPMENT TOSHIBA (AUSTRALIA) PTY. LIMITED
    "The situation is hopeless, we must take the next step." P.Casals
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.3 (Darwin)

    iQCVAwUBRJfutpj ExRNGDpoZAQFb/QP9H360XupArE3N uLZvI3PPpPIs2Ht 9JcLw
    P7hY1iz9Bl7A/7RBNVjJeegYByJw HX+8Zlgb/uBXMlTyS8KiCsIL OgeT3v+ycaZg
    W7VKcY4lCm1FZJR JkGvvwKtySTb54u uLoGU6kPEqrBS0v HxbhNrKacT4vNZN 9UM4
    NNBttvVDijk=
    =1l9n
    -----END PGP SIGNATURE-----

  • Mike Kent

    #2
    Re: unittest behaving oddly

    David Vincent wrote:
    [color=blue][color=green]
    > > import unittest
    > >
    > > class IntegerArithmen ticTestCase(uni ttest.TestCase) :
    > > def testAdd(self): ## test method names begin 'test*'
    > > assertEquals((1 + 2), 3)
    > > assertEquals(0 + 1, 1)[/color][/color]

    assertEquals is a member function, inherited from unittest.TestCa se, so
    you must call it as self.assertEqua ls. ForEx:

    class IntegerArithmen ticTestCase(uni ttest.TestCase) :
    def testAdd(self): ## test method names begin 'test*'
    self.assertEqua ls((1 + 2), 3)

    Comment

    • David Vincent

      #3
      Re: unittest behaving oddly

      -----BEGIN PGP SIGNED MESSAGE-----

      On 20/06/2006, at 23:15, Mike Kent wrote:
      [color=blue]
      > David Vincent wrote:
      >[color=green][color=darkred]
      >>> import unittest
      >>>
      >>> class IntegerArithmen ticTestCase(uni ttest.TestCase) :
      >>> def testAdd(self): ## test method names begin 'test*'
      >>> assertEquals((1 + 2), 3)
      >>> assertEquals(0 + 1, 1)[/color][/color]
      >
      > assertEquals is a member function, inherited from unittest.TestCa se, so
      > you must call it as self.assertEqua ls. ForEx:[/color]

      (Details deleted)


      Thank you Mike. That fixes most of my problems.

      The code quoted above was from my verbatim copy of the example from the
      doc strings of unittest.py, from my computer's Python library. I
      wonder how the example code could have been so badly wrong?


      regards

      David

      - --

      David A Vincent dvincent@toshib a-tap.com
      Software Engineer telephone +61 2 9850-2593
      RESEARCH AND DEVELOPMENT TOSHIBA (AUSTRALIA) PTY. LIMITED
      "The situation is hopeless, we must take the next step." P.Casals

      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.2.3 (Darwin)

      iQCVAwUBRJf/7pjExRNGDpoZAQE aKgQAgCVSdE/WJCunEdPfEIgCHk +dKMJHc2B6
      XWfc3WPvUcH5RL4 dQ18bbKNHEoHSZb MrN4CLKD55Lueea PbIgFgOpSkwoRRo akDi
      LWNbn7OWz2G1mbN gEVvqkOBhfK5l58 2kjzndtdsPBPD+P v/KiEC77/6dN27Fnl6e
      d0oKoDD3aac=
      =/dqt
      -----END PGP SIGNATURE-----

      Comment

      • Fredrik Lundh

        #4
        Re: unittest behaving oddly

        David Vincent wrote:
        [color=blue]
        > The code quoted above was from my verbatim copy of the example from the
        > doc strings of unittest.py, from my computer's Python library. I
        > wonder how the example code could have been so badly wrong?[/color]

        self-eating viruses on your machine ?

        $ more unittest.py

        ....

        Simple usage:

        import unittest

        class IntegerArithmen ticTestCase(uni ttest.TestCase) :
        def testAdd(self): ## test method names begin 'test*'
        self.assertEqua ls((1 + 2), 3)
        self.assertEqua ls(0 + 1, 1)
        def testMultiply(se lf):
        self.assertEqua ls((0 * 10), 0)
        self.assertEqua ls((5 * 8), 40)

        ....

        </F>

        Comment

        Working...