前提:
- python3
- 安装nose
结果:
nose目录下有子目录tests和mybag,在mybag下新建my_age.py, 内部有Students类,age属性。
tests目录下写Sutdents类的age属性测试
测试:nosetests
答案:
my_age.py
class Student(object):
@property
def birth(self):
return self._birth
@birth.setter
def birth(self, value):
self._birth = value
my_age_test.py
from nose.tools import assert_equal
from ..mybag.my_age import Student
def test_Student():
s = Student()
s.birth = "123"
assert_equal(s.birth, ‘123‘)
目录: