Help needed with unittest and global
Ian Hobson
ian at ianhobson.co.uk
Sun Jan 9 11:14:45 EST 2011
Hi all,
I am trying to develop a PyQt application, and I want to unittest it.
After three false starts, I am plainly unaware of something rather basic
- can some kind person please help me out?
This is a log to show what I have so far
D:\work\ian>type testAll.py
# coding=utf8
# testAll.py - run all tests.
import unittest
import sys
from PyQt4.QtGui import *
from testCubic import testCubic
global app
def main():
suite = unittest.TestLoader()
suite.loadTestsFromTestCase(testCubic)
unittest.TextTestRunner().run(suite)
if __name__=="__main__":
global app
app = QApplication(sys.argv) # set gloabl app
unittest.main()
D:\work\ian>type testCubic.py
# coding=utf8
# testCubic.py - tests the top level module
import unittest
global app
class testCubic(unittest.TestCase):
def test001_walkingSkeleton(self):
global app # use global version
app.processEvents() # fails
D:\work\ian>python testAll.py
E
======================================================================
ERROR: test001_walkingSkeleton (testCubic.testCubic)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\work\ian\testCubic.py", line 8, in test001_walkingSkeleton
app.processEvents() # fails
NameError: global name 'app' is not defined
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
D:\work\ian>
Thanks
Ian
More information about the Python-list
mailing list