python 测试

#测试单元

#Anaconda指的是一个开源的Python发行版本,其包含了conda、Python等180多个科学包及其依赖项 

import unittest  #测试单元

class TestAddition(unittest.TestCase):
    def setUp(self):  #开始
        print('Setting up the test')
        print(1)

    def tearDown(self):  #结束
        print(2)
        print('Tearing down the test')

    def test_twoPlusTwo(self):
        total = 2+2
        self.assertEqual(4, total);  #断言

if __name__ == '__main__':
    unittest.main(argv=[''], exit=False)
    %reset    #清除内存  如声明变量等之类的

# 一个线程

import threading
import time

class Crawler(threading.Thread):  #
    def __init__(self):  #初始化
        threading.Thread.__init__(self)
        self.done = False

    def isDone(self):
        return self.done

    def run(self):
        print(66)
        time.sleep(5)
        self.done = True  
        print('here')
        raise Exception('Something bad happened!')

t = Crawler()  #实例化
t.start()  #线程开始

while True:
    time.sleep(1)
    print(55)
    if t.isDone():  #True时候
        print('Done')
        break
    if not t.isAlive():  #线程崩溃 就重启线程
        t = Crawler()
        t.start()

 

posted @ 2019-07-10 17:08  追风zz  阅读(243)  评论(0编辑  收藏  举报