Help needed with unittest and global

Discussion in 'Python' started by Ian Hobson, Jan 9, 2011.

  1. Ian Hobson

    Ian Hobson Guest

    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
    Ian Hobson, Jan 9, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lol McBride
    Replies:
    4
    Views:
    255
    Lol McBride
    Nov 14, 2003
  2. Danny Shevitz

    help with unittest

    Danny Shevitz, Jan 23, 2004, in forum: Python
    Replies:
    0
    Views:
    253
    Danny Shevitz
    Jan 23, 2004
  3. Qiangning Hong

    unittest help

    Qiangning Hong, Mar 24, 2005, in forum: Python
    Replies:
    3
    Views:
    396
    Scott David Daniels
    Mar 24, 2005
  4. Paul  Moore
    Replies:
    1
    Views:
    379
    Paul Moore
    Oct 14, 2008
  5. Oltmans

    unittest help needed!

    Oltmans, Jan 14, 2010, in forum: Python
    Replies:
    3
    Views:
    275
    Phlip
    Jan 14, 2010
Loading...

Share This Page