반응형
setUp, tearDown
• test 마다 수행되는 초기화 및 정리 작업은 setUp(), tearDown()안에 넣으면 된다.
• 이 경우 매번 test_ 로 시작하는 함수가 불리기 전후로 setUp()과 tearDown()이 계속 불린다.
*
import unittest
class DestStringMethods(unittest.TestCase):
def setUp(self):
print 'setUp is called!!!'
def tearDown(self):
print 'tearDown is called!!!'
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
if __name__ == '__main__':
unittest.main()
• 제공되는 assertion. 그냥 assert 말고 다음거 써야한다.
반응형
'Programming' 카테고리의 다른 글
| 챗봇 특강 메모: RNN, 룰베이스, MDP 대화 알고리즘 (0) | 2026.05.20 |
|---|---|
| Python decorator coloring 패턴 정리 (0) | 2026.05.18 |
| Python decorator와 pytest 사용 패턴 정리 (0) | 2026.05.17 |
| Python decorator와 mixin 패턴 정리 (0) | 2026.05.17 |
| Matrix Completion과 추천 시스템 정리 (0) | 2026.05.17 |
