I am having trouble getting a test to pass. When I run the code it seems to work find, but in pytest it fails:
desk.py
class Dimension:
x = 0
y = 0
z = 0
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
class Desk:
def __init__(self, dimension):
self.dimension = dimension
@property
def dimension(self):
return self.__dimension
@dimension.setter
def dimension(self, d):
s = d.split(".")
self.__dimension = Dimension(int(s[0]), int(s[1]), int(s[2]))
@property
def is_large(self):
if self.dimension.x > 100:
return True
return False
test_desk.py
...
def test_is_large():
desk = Desk("5.5.5")
assert desk.is_large == False
...
I get AttributeError: 'str' object has no attribute 'x'
If I change to getter and setter methods it works find, but I would like to use decorators.
UPDATE:
I used python3 -m pytest
to run pytest using python3 and it works fine