Following is the structure of my tests in a file.
Class
setup
test01
test02
test03
teardown
I have a requirement to run specific code before and after each test.
For before, I could invoke that code from the setup. But for after the test, I am not able to figure how to do it. Obviously invoking the code from teardown would work for the last test, but how can I have it run for the tests in between?
Assuming that you're properly using a class descended from
unittest.TestCase
, then thesetUp
method is run before each test, and thetearDown
method is run after each test. Check the documentation. So it's completely feasible to put your code in those two methods.