Тестирование происходит только при соблюдении следующих условий:
1) класс начинается на 'Test'
2) класс наследует от unittest.TestCase (или иже с ним)
3) метод класса начинается на test
import unittest
from cat import Cat, Dog
class TestCat(unittest.TestCase):
#def test___init__(self):
# cat = Cat(name)
# assert False # TODO: implement your test here
# def test_eat(self):
# cat = Cat(name)
# self.assertEqual(expected, cat.eat(food))
# assert False # TODO: implement your test here
def test_eat_returns_Yummy_for_fish_after_creation_with_Tom(self):
cat = Cat('Tom')
self.assertEqual('Yummy!', cat.eat('fish'))
self.assertEqual('Yummy!', cat.eat('fish'))
# self.assertEqual('Yummy!', cat.eat('eggs'))
# self.assertEqual('Yummy!', cat.eat('meat'))
def test_eat_returns_Yummy_for_fish_after_creation_with_Tom2(self):
cat = Cat('Tom')
self.assertEqual('Yummy!', cat.eat('fish'))
self.assertEqual('Yummy!', cat.eat('fish'))
class TestDog(unittest.TestCase):
#def test___init__(self):
# cat = Cat(name)
# assert False # TODO: implement your test here
# def test_eat(self):
# cat = Cat(name)
# self.assertEqual(expected, cat.eat(food))
# assert False # TODO: implement your test here
def test_eat_returns_Yummy_for_fish_after_creation_with_Tom(self):
dog = Dog('Tom')
self.assertEqual('Yummy!', dog.eat('fish'))
self.assertEqual('Yummy!', dog.eat('fish'))
# self.assertEqual('Yummy!', cat.eat('eggs'))
# self.assertEqual('Yummy!', cat.eat('meat'))
def test_eat_returns_Yummy_for_fish_after_creation_with_Tom2(self):
dog = Dog('Tom')
self.assertEqual('Yummy!', dog.eat('fish'))
self.assertEqual('Yummy!', dog.eat('fish'))
class TestDog(unittest.TestCase):
def test(self):
print('Test')
if __name__ == '__main__':
unittest.main()