Tutorial: Unit Testing

Index of All Documentation » Wing Pro Tutorial »

Wing Pro'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.

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.

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.

Debugging Tests

Now run the failed testFailure in the debugger by clicking on it in the Testing tool and pressing Debug Tests at the top of the tool. Wing should stop at the exception and you can use the debugger on the test as you would for any other Python code.


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 with Environment under the Testing tab of Project Properties or in the File Properties for the unit test file.

See Unit Testing for details.