国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

解決 TypeError: object of type ‘float‘ has no len() 問題 unittest單元測試框架 ddt data 數(shù)據(jù)驅動

這篇具有很好參考價值的文章主要介紹了解決 TypeError: object of type ‘float‘ has no len() 問題 unittest單元測試框架 ddt data 數(shù)據(jù)驅動。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

1 問題

在unittest框架下,運用ddt和data模塊進行數(shù)據(jù)驅動,腳本外存儲數(shù)據(jù)時,報錯。

TypeError: object of type 'float' has no len()

對象數(shù)據(jù)類型不夠存儲。

2 原因

excel文件中的數(shù)據(jù)單元格沒有添加'英文的單引號,把數(shù)字當成文本來處理。電話號為11超出float數(shù)據(jù)類型的存儲范圍,文本就當成了字符串數(shù)據(jù)類型來處理。

3 辦法

將單元格內添加'
例如下圖:
解決 TypeError: object of type ‘float‘ has no len() 問題 unittest單元測試框架 ddt data 數(shù)據(jù)驅動,測試,python,單元測試,selenium,測試工具,chrome
附上在unittest框架下,運用ddt和data模塊進行數(shù)據(jù)驅動,執(zhí)行測試用例,以QQ注冊頁面為例子,代碼如下:文章來源地址http://www.zghlxwxcb.cn/news/detail-601367.html

# 導入自動化包
from selenium import webdriver
import time
# 導入單元測試框架
import unittest
from ddt import ddt,data
# 將excel數(shù)據(jù)轉化為列表字典的方法導入
from excel_turnto_listdic import ExcelUtil

import warnings

# 創(chuàng)建類,繼承TestCase類
@ddt
class E01(unittest.TestCase):
    '''測試用例的數(shù)據(jù)'''
    obj1 = ExcelUtil(r"./Data/abc.xlsx")
    dicData = obj1.dic_data()
    # setUpClass方法需要用修飾器
    @classmethod
    def setUpClass(self):
        warnings.simplefilter('ignore', ResourceWarning)
    def setUp(self) -> None:
        pass
    #第一條測試用例
    @data(*dicData)
    def test_t_1(self,para): # data中的數(shù)據(jù)以參數(shù)para形式傳入測試用例
        # 創(chuàng)建瀏覽器對象
        driver = webdriver.Chrome()
        # 打開網址
        driver.get("https://ssl.zc.qq.com/v3/index-chs.html")
        time.sleep(2)
        # 在昵稱文本框輸入合法字符
        driver.find_element_by_id("nickname").send_keys(para["username"])
        time.sleep(2)
        # 輸入有效密碼
        driver.find_element_by_id("password").send_keys(para["password"])
        time.sleep(2)
        # 輸入有效手機號碼
        driver.find_element_by_id("phone").send_keys(para["phonenumber"])
        time.sleep(2)
        # 點擊【發(fā)送驗證碼】按鈕
        driver.find_element_by_id("send-sms").click()
        time.sleep(2)
        # 輸入驗證碼
        driver.find_element_by_xpath('//*[@id="code"]').send_keys(para["vcode"])
        time.sleep(2)
        # 點擊“同意協(xié)議”
        driver.find_element_by_xpath('/html/body/div[3]/div[2]/div[1]/form/div[8]/label/img[2]').click()
        time.sleep(2)
        # 點擊【立即注冊】按鈕
        driver.find_element_by_id("get_acc").click()
        time.sleep(2)
        driver.quit()
    def tearDown(self) -> None:
        pass

    @classmethod
    def tearDownClass(cls) -> None:
        pass
if __name__ == '__main__':
    unittest.main()
    # path = os.path.dirname(__file__)
    # print(path)
    # site01 = unittest.defaultTestLoader.discover(path, pattern="test_t_1.py")
    # with open(r'./re.txt','wb') as f:
    #     runner = unittest.TextTestRunner(f,descriptions="測試報告",verbosity=2)
    #     runner.run(site01)

到了這里,關于解決 TypeError: object of type ‘float‘ has no len() 問題 unittest單元測試框架 ddt data 數(shù)據(jù)驅動的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯(lián)網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 解決報錯TypeError: Object of type int32 is not JSON serializable

    當我們嘗試將 numpy int32 對象轉換為 JSON 字符串時,會出現(xiàn) Python“TypeError: Object of type int32 is not JSON serializable”。 要解決該錯誤,請先將 numpy int 轉換為 Python 整數(shù),然后再將其轉換為 JSON,例如 下面是錯誤如何發(fā)生的示例。 我們嘗試將 numpy int32 對象傳遞給 json.dumps() 方法,但

    2024年02月06日
    瀏覽(27)
  • 【解決】MissingReferenceException: The object of type ‘GameObject‘ has been destroyed 觀察者模式 監(jiān)聽物體被銷毀

    【解決】MissingReferenceException: The object of type ‘GameObject‘ has been destroyed 觀察者模式 監(jiān)聽物體被銷毀

    MissingReferenceException: The object of type ‘Text’ has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. 該情況發(fā)生于我的 觀察者模式 在 重新加載當前場景 時 監(jiān)聽的物體被 銷毀 如上所示錯誤,通過分析,定位到錯誤是在觀察

    2024年02月11日
    瀏覽(19)
  • python報‘AttributeError: type object ‘datetime.datetime‘ has no attribute ‘datetime‘‘錯誤的原因及解決方案

    python報‘AttributeError: type object ‘datetime.datetime‘ has no attribute ‘datetime‘‘錯誤的原因及解決方案

    在運行以下代碼時出現(xiàn)報錯AttributeError: type object ‘datetime.datetime’ has no attribute ‘datetime’ 原因:在導入模塊使用from datetime import datetime,由于包名和類名一樣,導致系統(tǒng)識別出現(xiàn)混亂,無法知道哪個是具體包和類 解決方案:直接使用import datetime進行導包即可

    2024年02月13日
    瀏覽(22)
  • TypeError: ‘float‘ object is not subscriptable 已解決

    TypeError: ‘float‘ object is not subscriptable 已解決

    其實就是個小問題,但是爆出來的時候也很莫名其妙。因為之前都跑得好好的,只是換了不同的文件去跑才出的問題,關鍵是不同的文件要處理的內容和格式都是完全一樣的,一個順利跑完,一個就報TypeError: ‘float’ object is not subscriptable這個錯,就非常無語。接下來就是看

    2024年02月11日
    瀏覽(35)
  • 【Python】成功解決TypeError: ‘float‘ object is not iterable

    【Python】成功解決TypeError: ‘float‘ object is not iterable

    【Python】成功解決TypeError: ‘float’ object is not iterable ?? 個人主頁:高斯小哥 ?? 高質量專欄:Matplotlib之旅:零基礎精通數(shù)據(jù)可視化、Python基礎【高質量合集】、PyTorch零基礎入門教程?? 希望得到您的訂閱和支持~ ?? 創(chuàng)作高質量博文(平均質量分92+),分享更多關于深度學習、

    2024年03月09日
    瀏覽(34)
  • 【趣解Bug】解決‘WebDriver‘ object has no attribute ‘find_element_by_xpath‘問題

    【趣解Bug】解決‘WebDriver‘ object has no attribute ‘find_element_by_xpath‘問題

    今天換了個電腦,之前在舊電腦里運行的自動化測試腳本突然失靈了,真的讓人頭禿,先看看問題 報錯信息中顯示WebDriver沒有屬性find_element_by_xpath,這怎么可能,這些代碼在之前電腦里運行了千百遍,不可能說失效就失效的,悲傷持續(xù)了一秒鐘,我就拿出百度大法,果然有解

    2023年04月10日
    瀏覽(22)
  • 解決selenium的WebDriver object has no attribute ‘find_element_by_xpath‘問題

    解決selenium的WebDriver object has no attribute \\\'find_element_by_xpath’問題 在使用selenium操作瀏覽器時,常見的一種定位元素的方式就是Xpath定位。但有時候會出現(xiàn)WebDriver object has no attribute \\\'find_element_by_xpath’的錯誤提示,意思是WebDriver對象沒有該方法。 這通常是因為引入selenium包時未正

    2024年02月10日
    瀏覽(18)
  • 成功解決AttributeError: module ‘numpy‘ has no attribute ‘float‘.

    AttributeError: module ‘numpy’ has no attribute ‘float’. np.float was a deprecated alias for the builtin float . To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here. The aliases was originally deprecated in NumPy 1.20; for

    2024年02月16日
    瀏覽(25)
  • Python之解決報錯:TypeError: unsupported operand type(s) for /: ‘builtin_function_or_method‘ and ‘float‘

    Python之解決報錯:TypeError: unsupported operand type(s) for /: ‘builtin_function_or_method‘ and ‘float‘

    開門見山哈家人們,首先解決方法:查找報錯內容相關的代碼,找到源頭,添加小括號。 解釋如下: 在運行Python程序的時候,報了個錯,找了半天沒找到什么原因。 因為給的報錯信息在94行,反反復復盯著94行以及附近找了半個多小時,最后百度了半天發(fā)現(xiàn)問題出在了19行

    2024年02月15日
    瀏覽(39)
  • YOLOV5 | AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘ 問題解決 親測有效

    YOLOV5 | AttributeError: ‘Upsample‘ object has no attribute ‘recompute_scale_factor‘ 問題解決 親測有效

    如圖: 1.點擊報錯行該路徑,進入編輯頁 2.將原代碼(153-154行)修改為如下所示(155行): 即: 保存后再次運行detect.py,即可: 來看看訓練結果吧 運行detect.py之前,應該將YOLOV5對應的權重文件放到項目文件夾下: 這里提供官方權重文件,可點擊下方鏈接自行下載: YOLOv

    2024年02月13日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包