Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Always write unit test cases in a file which starts with test_something.py
- To run a test write on terminal
- python -m unittest test_something.py
- in class test_something.py define a class and inherit from unittest.TestCase class ClassName(object):
- """docstring for ClassName"""
- def __init__(self, arg):
- super(ClassName, self).__init__()
- self.arg = arg
- write the main function in the file
- if '__name__' = '__main__':
- unittest.main()
- and then run
- python test_something.py
- both will give some result like:
- Ran 1 test in 0.000s
- write all function names like test_something otherwise that test function will not run
- setUp()
- and
- tearDown() methods run before and after of each test if defined
- to run something before every test case
- and to run something after every test case run:
- setUpClass
- and tearDownClass classmethod
- from unittest.mock import patch
- use patch as derocator or context manager
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement