I have a python module/script which does a few of these
- At various nested levels inside the script I take command line inputs, validate them, apply sensible defaults
- I also check if a few directories exist
The above are just two examples. I am trying to find out what is the best "strategy" to test this. What I have done is that I have constructed wrapper functions around raw_input
and os.path.exists
in my module and then in my test I override these two functions to take input from my array list or do some mocked behaviour. This approach has the following disadvantages
- Wrapper functions just exist for the sake of testing and this pollutes the code
- I have to remember to use the wrapper function in the code everytime and not just call
os.path.exists
orraw_input
Any brilliant suggestions?