473,594 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
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$


- --

David A Vincent dv******@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-----

Jun 20 '06 #1
3 3423
David Vincent wrote:
import unittest

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


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)

Jun 20 '06 #2
-----BEGIN PGP SIGNED MESSAGE-----

On 20/06/2006, at 23:15, Mike Kent wrote:
David Vincent wrote:
import unittest

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


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


(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 dv******@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-----

Jun 20 '06 #3
David Vincent wrote:
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?


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>

Jun 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2309
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 Test_rmlutils(unittest.TestCase):
0
1284
by: Danny Shevitz | last post by:
Why doesn't the following code snippet work? The error is ImportError: No module named myTestCase2 TIA, Danny %<--------------------------------------------------------------------
0
2035
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 TestCase.skipIf(expr, msg): skips if expr is true These can be called either in setUp() or in the test methods. I also added reporting of skipped tests to TestResult, _TextTestResult and
1
1501
by: Thomas Heller | last post by:
I'm trying to integrate some doctest tests with unittest. The tests must be exposed as one or more subclasses of unittest.TestCase, so I'm collecting them with a call to doctest.DocTestSuite(), and then add them to a TestCase class I have created. The tests seem to run, but they always seem to succeed - I have no idea why. Any ideas? Thomas ---snip---
41
10259
by: Roy Smith | last post by:
I've used the standard unittest (pyunit) module on a few projects in the past and have always thought it basicly worked fine but was just a little too complicated for what it did. I'm starting a new project now and I'm thinking of trying py.test (http://codespeak.net/py/current/doc/test.html). It looks pretty cool from the docs. Is there anybody out there who has used both packages and can give a comparative review?
7
2064
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 old lines at the end: if __name__ == "__main__": unittest.main() This is great, because each of the modules are runnable, and I can select classes or tests to run on the commandline if I want to. However, running all the tests from e.g. a...
2
2447
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 assert the output. It's reasonable to use "unittest" here, but the problem is that "unittest" doesn't support (== I haven't found how) dynamic creation of tests. I thought it would be very easy, but due to lack of closures in Python (more...
0
2303
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 self.sampler = DisasterSampler()
1
3935
by: Chris Fonnesbeck | last post by:
I have a module for which I am trying to code a unit test. However, when I run unittest.main(), I get: In : import PyMC In : PyMC.unittest.main() ---------------------------------------------------------------------- Ran 0 tests in 0.000s
0
7946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7876
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8234
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6654
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5408
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2385
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.