Python में Testing का परिचय
Alexander Levin
Data Scientist
.setUp() - असली टेस्ट से पहले fixture तैयार करने के लिए कॉल होने वाली method.tearDown() - टेस्ट method के बाद environment साफ करने के लिए कॉल होने वाली methodimport unittest
class TestLi(unittest.TestCase):
# Fixture setup method
def setUp(self):
self.li = [i for i in range(100)]
# Fixture teardown method
def tearDown(self):
self.li.clear()
# Test method
def test_your_list(self):
self.assertIn(99, self.li)
self.assertNotIn(100, self.li)
सही syntax: setUp में capital U और tearDown में capital D.
class TestLi(unittest.TestCase):
# Fixture setup method
def setUp(self):
self.li = [i for i in range(100)]
# Fixture teardown method
def tearDown(self):
self.li.clear()
कमांड: python3 -m unittest test_in_list.py
.setUp() और .tearDown() के साथ रन का आउटपुट:

.set_up() के साथ रन का आउटपुट:

.setUp() method implement करें.tearDown() method implement करें.setUp() - असली टेस्ट से पहले test fixture तैयार करने के लिए कॉल होने वाली method..tearDown() - टेस्ट method के बाद environment साफ करने के लिए कॉल होने वाली method.Python में Testing का परिचय