使用unittest将对象从mainthread传递给我的测试用例

时间:2012-04-19 10:54:41

标签: python unit-testing testing

我是python的新手,刚刚开始开发linux应用程序自动化。

我正在尝试的方案是

thread.py ---将调用所有主设备线程并从testcase

加载测试

admincase.py ---举行我的案例测试..

我无法做的是我想在加载测试时将某些对象从thread.py传递给admincase.py。我该怎么做..

我尝试传递的对象是( EppQueue

thread.py代码

import threading
import sys
import time
import logging
import os
import Queue
from EPP import EPP
import ldtp
import ldtputils
from functions import functions
from admincases import admincases
import unittest

#logging.basicConfig(level=logging.DEBUG,
#                    format='(%(threadName)-10s) %(message)s',
#                    )
class inittest(unittest.TestCase):
    global fun
    global EppQueue
    global window_name

    def cleanup(epp_port):
        if os.path.exists(epp_port):
            os.unlink(epp_port)

    def start_threads(EppQueue,server_ip,epp_port):
        epp = EPP
        EPP1 = threading.Thread(name='EPP', target=epp, args=(server_ip,54321,epp_port,EppQueue,))
        EPP1.setDaemon(True)
        EPP1.start()
        return epp 
    fun = functions()
    EppQueue = Queue.Queue(1)
    server_ip ='192.168.10.125'
    epp_port='/dev/ttyS17'
    print "Starting"
    cleanup(epp_port)
    print "Clean up Over"
    epp = start_threads(EppQueue,server_ip,epp_port)
    raw_input("###### Please Start the main appilcation in the ATM and hit a KEY to continue ############")
    check = 0
    while check == 0:
        window_name = fun.start_up_verify('atm_main_app')
        if any(window_name):
            check = 1
        else:
            check = 0
    if not any(window_name):
        print "Please start the application and run the test"
        sys.exit(0) 
    else:
        print window_name
        print "SYSTEM IS READY TO PERFORM TEST"
        raw_input("###### HIT ANY KEY TO START UNIT TEST ############")
        raw_input("kkk")    
        test = unittest.defaultTestLoader.loadTestsFromName("admincases")
        unittest.TextTestRunner(verbosity=2).run(test)
    raw_input("keyy")
    print "final"

admincase.py代码

import unittest
from functions import functions
import time
import Queue

class admincases(unittest.TestCase):
    global fun
    global EppQueue
    global window_name

    def test_case_1(self):
        print "test case 1"
        window_name = 'frmatm_main_app'
        fun.send_queue(self.EppQueue,"send_keys,&&&&&")
        fun.verify_screen(window_name,"ico0") 
        fun.send_queue(self.EppQueue,"send_keys,C")
        fun.verify_screen(window_name,"ManagementFunctions") 
        fun.send_queue(self.EppQueue,"send_keys,001234")
        fun.verify_screen(window_name,"MainMenu")
        fun.send_queue(self.EppQueue,"send_keys,1")
        fun.verify_screen(window_name,"Diagnostics")
        fun.send_queue(self.EppQueue,"send_keys,1")
        fun.verify_screen(window_name,"TerminalStatus")
        fun.send_queue(self.EppQueue,"send_keys,2")
        time.sleep(10)
        fun.send_queue(self.EppQueue,"send_keys,####****")


    fun = functions()
    #EppQueue = Queue.Queue(1)

需要一些帮助...

0 个答案:

没有答案