我有這段代碼需要檢查是否partialExpectedTitle包含在documentTitle. 但是之后我得到一個錯誤,我們有一個斷言錯誤。是否in并且not in僅在串列中有效?還是我讓它在一個字串中作業?
documentTitle = context.mailTrapPage.getExcelTitle().text.strip()
excelTitle = download_path "/" documentTitle
excelWorkbook = o.load_workbook(excelTitle)
print("partialExpectedTitle is " partialExpectedTitle)
print("documentTitle is " documentTitle)
assert partialExpectedTitle in documentTitle is True
錯誤:
assert partialExpectedTitle in documentTitle is True
AssertionError
Captured stdout:
['1 - AAAAAA qlgmdfol']
partialExpectedTitle is courses20220913_1110
documentTitle is courses20220913_111050.xlsx
uj5u.com熱心網友回復:
由于operator chaining,運算式x in y is True等同于(x in y) and (y is True),這可能不是您的想法。
那么什么時候需要is True呢?幾乎沒有。僅當您需要將實際值True與“真實”值(例如 17 或“hello”)區分開來時才有意義。
對于您在評論中的示例,請使用not運算子:assert not elementLocator.is_enabled。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/506695.html
