[問題] 如何測試 sub function
# -*- coding: utf-8 -*-
def run():
def the_name():
if not hasattr(the_name, 'name'):
the_name.name = 'test'
return the_name.name
for i in range(3):
print(the_name())
run()
print('')
run()
print('')
run()
各位好,我想針對上面的 code 寫單元測試
主要是想判斷第一次執行時還沒有 the_name.name
執行第一次之後便存在這個 property 因此直接回覆 the_name.name
本是想用 self.assertFalse(getattr(run.the_name.name))
不過顯然不能這樣用,不知道怎麼可以達成需求
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.124.224.43
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1526623070.A.63B.html
推
05/19 05:48,
7年前
, 1F
05/19 05:48, 1F
→
05/19 05:48,
7年前
, 2F
05/19 05:48, 2F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章