Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Testing & Debugging

Ben Golder edited this page Nov 1, 2017 · 2 revisions

Testing

To run the test suite, use:

make test

If you'd like to see coverage results you can use:

make test.coverage

Some of the tests take longer to run than others. Some of them need to create and read pdfs on the file system. These do not run local by default. But they do run during Travis builds. If you'd like to include these slower tests you can run them with:

make test.deluxe

To target a particular test, you can add a SCOPE variable. For example if I want to just test that an org user can only see applications to their own organization on the app index page, I would run:

make test \
    SCOPE=intake.tests.views.test_admin_views.TestApplicationIndex.test_that_org_user_can_only_see_apps_to_own_org

Alternatively you could run all the tests for the admin views with:

make test \
    SCOPE=intake.tests.views.test_admin_views

As you can see, the SCOPE variable should use the syntax of a python import path.

Behave Tests

You can run the browser test suite using the following command:

make test.behave

The Behave tests open a live connection to Browserstack. Consequently, these tests will not run without an internet connection.

Debugging and introspection

The requirements include a few libraries that are helpful for debugging and exploring functionality.

ipdb breakpoints

To set an interactive breakpoint somewhere in the code, insert this line:

import ipdb; ipdb.set_trace()

Here is a Sublime Text snippet that lets you type ipd as shortcut for the line above. Go to Tools > Developer > New Snippet while a python file is open.

The execution will enter an interactive prompt at this point in the code, with tab completion and a variety of shortcuts available.

  • s or step: step into the next execution frame.
  • c or continue: Continue exection
  • u or up: Move up one frame in the stack trace.
  • d or down: Move down one frame in the stack trace.
  • n or next: continue to the next line.
  • ll: show the lines of code in the current function.
  • pp: pretty print an object. For example, (pp my_object).

shell_plus interactive python shell

To load an interactive ipython prompt with tab completion, models, and other useful things preloaded, run this shell command:

./manage.py shell_plus

Any print commands will pretty print by default. Tab completion is available.