I’ve written a function which opens a vim editor with the given filename when called.. How can I do the unittest of these types of operations….
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To unit test something like this you must mock/stub out your dependencies. In this case lets say you are launching vim by calling os.system(“vim”).
In your unit test you can stub out that function call doing something like:
For more details on mocking and stubbing take a look at this article
Update: I added the try/finally to restore the original system function as suggested by Dave Kirby