zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    课堂例子验证
    大道至简第三章读后感
    动手动脑例子验证
    各数相加的思路、流程图、源代码及实现截图
    大道至简第二章读后感
    《大道至简》第一章读后感
    个人冲刺08
    个人冲刺07
    构建之法读后感04
    个人冲刺06
  • 原文地址:https://www.cnblogs.com/zhangchen-sx/p/11165166.html
Copyright © 2011-2022 走看看