用法:
doctest.IGNORE_EXCEPTION_DETAIL
指定時,如果引發預期類型的異常,則預期異常的示例通過,即使異常詳細信息不匹配。例如,如果引發的實際異常是
ValueError: 3*14
,則期望ValueError: 42
的示例將通過,但會失敗,例如,如果引發TypeError
。它還將忽略 Python 3 doctest 報告中使用的模塊名稱。因此,無論測試是在 Python 2.7 還是 Python 3.2(或更高版本)下運行,這兩種變體都可以使用指定的標誌:
>>> raise CustomError('message') Traceback (most recent call last): CustomError: message >>> raise CustomError('message') Traceback (most recent call last): my_module.CustomError: message
請注意,
ELLIPSIS
也可用於忽略異常消息的詳細信息,但根據模塊詳細信息是否作為異常名稱的一部分打印,此類測試仍可能失敗。使用IGNORE_EXCEPTION_DETAIL
和 Python 2.3 中的詳細信息也是編寫不關心異常詳細信息但在 Python 2.3 或更早版本下繼續通過的 doctest 的唯一明確方法(這些版本不支持 doctest 指令並將它們作為無關的評論)。例如:>>> (1, 2)[3] = 'moo' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: object doesn't support item assignment
通過指定標誌的 Python 2.3 和更高版本的 Python,即使 Python 2.4 中的細節更改為 “does not” 而不是 “doesn’t”。
在 3.2 版中更改:doctest.IGNORE_EXCEPTION_DETAIL現在也忽略與包含被測異常的模塊相關的任何信息。
相關用法
- Python doctest.script_from_examples用法及代碼示例
- Python dask.dataframe.Series.apply用法及代碼示例
- Python dask.dataframe.to_records用法及代碼示例
- Python distributed.protocol.serialize.register_generic用法及代碼示例
- Python dask.dataframe.DataFrame.applymap用法及代碼示例
- Python dask.dataframe.Series.clip用法及代碼示例
- Python dask.array.stats.ttest_ind用法及代碼示例
- Python dict()用法及代碼示例
- Python dask.array.ma.masked_values用法及代碼示例
- Python dask.array.divmod用法及代碼示例
- Python dask.compute用法及代碼示例
- Python dask.dataframe.Series.prod用法及代碼示例
- Python dask.dataframe.Series.fillna用法及代碼示例
- Python dask.dataframe.DataFrame.sub用法及代碼示例
- Python dask.bag.Bag.frequencies用法及代碼示例
- Python dask.config.set用法及代碼示例
- Python dask.dataframe.compute用法及代碼示例
- Python dask_ml.wrappers.ParallelPostFit用法及代碼示例
- Python dask.array.negative用法及代碼示例
- Python datetime astimezone()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 doctest.IGNORE_EXCEPTION_DETAIL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。