gpt4 book ai didi

python - 对 python 类属性进行单元测试

转载 作者:行者123 更新时间:2023-11-30 21:53:17 24 4
gpt4 key购买 nike

假设我有一个类:

class Player(object):
def __init__(self):
self.goal = ''

@property
def goal(self):
return self.goal

考虑到属性goal不可调用,是否可以对其编写单元测试?

最佳答案

怎么样:

def test_goal_property(self):
dummy_player = Player()

self.assertEqual(dummy_player.goal, '')

def test_goal_property(self):
dummy_player = Player()
dummy_player.goal = 'something'

self.assertEqual(dummy_player.goal, 'something')

关于python - 对 python 类属性进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59732625/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com