0

Sorry, I'm not totally sure what it is I'm looking for, but can someone tell me how to best accomplish this?

I have a set of functions that run some test. However, there are some commands that I want to run before and after each test. What is the cleanest way to do this without copying those commands into the beginning and end of every test function?

user2503227
  • 117
  • 4
  • 12
  • 2
    There are a bunch of testing frameworks that let you specify this. – cs95 Jan 07 '18 at 01:30
  • 1
    You can also use a decorator. [This is a comprehensive explanation](https://stackoverflow.com/questions/739654/how-to-make-a-chain-of-function-decorators/1594484#1594484) and there's plenty of introductory material/examples online. – Patrick Haugh Jan 07 '18 at 01:31

1 Answers1

0

If you are using unittest library, you can use the functions setUp() and tearDown() in you test class. setUp() is run before each test function and tearDown() after. For examples you can use this link:

https://docs.python.org/3/library/unittest.html

Ali E
  • 1
  • 1