[英]Can I unit test an inner function in python?
有沒有什么辦法來寫unittests
或doctests
的innerfunc
?
def outerfunc():
def innerfunc():
do_something()
return innerfunc()
只有當你提供一種提取內部函數對象本身的方法時,例如
def outerfunc(calltheinner=True):
def innerfunc():
do_something()
if calltheinner:
return innerfunc()
else:
return innerfunc
如果你的外部功能堅持將內部完全隱藏在自身內部(在適當地哄騙時不要讓它滲透到外面),你的單元測試無法擊敗這種對極端和完全隱私的強烈要求;-)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.