Tutorial: Unit Testing
Wing's Testing tool makes it easy to run and debug units tests written for the unittest, doctest, pytest, nose, and Django unit testing frameworks.
Let's try this out now. First, open up Project Properties and under the Testing tab insert a Test File Pattern that is set to Glob / Wildcard and test_*.py. This tells Wing which of your project files are unit test files. Press OK or Apply and bring up the Testing tool from the Tools menu. This should now contain an entry for the file test_example1.py:
Next comment out the line that reads PromptToContinue in example1.py so that the module can be loaded by the tests without prompting. One way to do this is to click on the line and use Toggle Block Comment from the Source menu.
Then press Run Tests in the Testing tool. You should see two of the three tests pass, and one will fail. You can expand the tree to see details of the failed tests, including any output printed by the test and the exception that occurred. Double clicking on the test results and exception will take you to the relevant code.
Now run the failed testFailure in the debugger by right clicking on it and selecting Debug Test. Wing should stop at the exception and you can use the debugger on the test as you would for any other Python code.
Note that you can also run tests from the editor by clicking on the test you want to run and selecting Run Tests at Cursor from the Testing menu.
When unit tests are run in the Testing tool, by default they run in the same environment that is used for debugging and executing code. This can be changed by specifying a Launch Configuration to use instead, with Environment under the Testing tab of Project Properties or File Properties on the unit test file.