引用python手册(27.6.4。Testing
Warnings):
import warningsdef fxn(): warnings.warn("deprecated", DeprecationWarning)with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") # Trigger a warning. fxn() # Verify some things assert len(w) == 1 assert issubclass(w[-1].category, DeprecationWarning) assert "deprecated" in str(w[-1].message)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)