shawngn
shawngn

Reputation: 21

Unit testing on a python class property

Suppose I have a class:

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

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

Is it possible to write a unit test on the property goal, given that it is not callable?

Upvotes: 1

Views: 762

Answers (1)

Giorgos Myrianthous
Giorgos Myrianthous

Reputation: 39830

How about:

def test_goal_property(self):
    dummy_player = Player()

    self.assertEqual(dummy_player.goal, '')     

or

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

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

Upvotes: 4

Related Questions