摘要:基礎(chǔ)數(shù)據(jù)獲取地址端口發(fā)送訂閱主題請求參數(shù)獲取這里是發(fā)送的函數(shù)
# -*- coding:utf-8 -*-from multiprocessing import Processimport paho.mqtt.publish as publishfrom Data.data import *import paho.mqtt.subscribe as subscribefrom common.yaml_common_method import *import time,json,yaml,os"""基礎(chǔ)數(shù)據(jù)yaml獲取"""data = yaml_method_read("data")host = data["host"]#IP地址prot = data["port"]#端口pub_url = data["pub_url"]+"/register"#發(fā)送sub_url = data["sub_url"]+"/register/response"#訂閱"""主題請求參數(shù)yaml獲取"""publish_yaml = yaml_method_read("publish")publish_msg = publish_yaml["upload_service"]client_id = time.strftime("mq:test:%Y%m%d%H%M%S",time.localtime(time.time()))class Mqtt_method_info(): def mqtt_publish(self): #這里是發(fā)送的函數(shù) msg = publish_msg print("------------------------------Send_sub------------------------------") print(pub_url) print("----------------------------Send_message----------------------------") print(msg) msg = json.dumps(msg) publish.single(pub_url, msg, qos=1, hostname=host, port=prot, client_id=client_id) print("------------------------------End_send------------------------------") def mqtt_subscribe(self): #這里是訂閱的函數(shù) print("--------------------------Subscribe_topics--------------------------") print(sub_url) msg = subscribe.simple(sub_url, qos=1, hostname=host, port=prot, client_id=client_id) msg_payload = json.loads(msg.payload.decode("utf-8")) print("---------------------------Return_message----------------------------") print(msg_payload) yaml_method_write("mqtt_return_data",msg_payload) def implement(self): pub = Process(target=Mqtt_method_info().mqtt_publish)#發(fā)送線程 sub = Process(target=Mqtt_method_info().mqtt_subscribe)#訂閱線程 sub.start() time.sleep(1) pub.start() sub.join() print("執(zhí)行完畢")if __name__ == "__main__": Mqtt_method_info().implement()
?這里講一下python-mqtt測試腳本:
我們會使用到python的paho-mqtt庫,同樣pip安裝下就行,失敗的話大部分是需要用鏡像站的情況
這份代碼分為yaml文件讀取發(fā)送的數(shù)據(jù),這里只有操作的方法,大家如果需要使用可以把發(fā)送、訂閱的函數(shù)中修改,只運(yùn)行方法,然后自己再通過各種文件管理數(shù)據(jù)
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/121071.html
摘要:正確合理地實施自動化測試,能夠快速全面地對軟件進(jìn)行測試,從而提高軟件質(zhì)量,節(jié)省經(jīng)費(fèi),縮短產(chǎn)品發(fā)布周期。自動化測試工具能實現(xiàn)百分之百的測試覆蓋率。年題以下測試項目不適合采用自動化測試的是。故正確答案為年題自動化測試的優(yōu)勢不包括。 自動化測試是近些年的一個熱點,為了更加快速、有效地對軟件進(jìn)行測試,提高軟件產(chǎn)品的質(zhì)量,必然會利用...
摘要:事實上,自動化測試是相對于手動的。減少人為的錯誤自動化測試是機(jī)器完成,不存在執(zhí)行過程中人為的疏忽和錯誤,測試設(shè)計完全決定了測試的質(zhì)量,可以降低減少人為造成的錯誤。而接口自動化測試,主要是對接口進(jìn)行測試。 今年6月份,由于經(jīng)濟(jì)壓力讓我下定決心進(jìn)階自動化測試,已經(jīng)24的我做了3年功能測試,坐標(biāo)廣...
摘要:而現(xiàn)實是,很多團(tuán)隊在實施自動化測試的過程中,并未取得良好的質(zhì)量效果,這主要是因為學(xué)習(xí)自動化測試有兩大難點自動化測試本身擁有一定的技術(shù)門檻最大的難點是需要大量的實戰(zhàn)經(jīng)驗。 ...
摘要:在上次的自動化測試系列二自動化測試系列二中為大家大體介紹了測試的概念及在豬齒魚中的實踐展開,本文主要圍繞測試進(jìn)行概念介紹及中的實踐展開。手動測試要求測試人員在每個元素上手動執(zhí)行每個測試。主要是用于回歸測試和同一軟件的新版本測試。 UI 測試是一種測試類型,也稱為用戶界面測試,通過該測試,我們...
閱讀 2439·2021-11-11 16:54
閱讀 2676·2021-09-26 09:47
閱讀 4014·2021-09-08 09:36
閱讀 2761·2021-07-25 21:37
閱讀 948·2019-08-30 15:54
閱讀 2563·2019-08-30 14:22
閱讀 3275·2019-08-30 13:57
閱讀 2682·2019-08-29 17:17