Testing JupyterHub

Unit test help validate that JupyterHub works the way we think it does, and continues to do so when changes occur. They also help communicate precisely what we expect our code to do.

JupyterHub uses pytest for all our tests. You can find them under jupyterhub/tests directory in the git repository.

Running the tests

  1. Make sure you have completed Setting up a development install. You should be able to start jupyterhub from the commandline & access it from your web browser. This ensures that the dev environment is properly set up for tests to run.

  2. You can run all tests in JupyterHub

    pytest -v jupyterhub/tests
    

    This should display progress as it runs all the tests, printing information about any test failures as they occur.

    If you wish to confirm test coverage the run tests with the --cov flag:

    pytest -v --cov=jupyterhub jupyterhub/tests
    
  3. You can also run tests in just a specific file:

    pytest -v jupyterhub/tests/<test-file-name>
    
  4. To run a specific test only, you can do:

    pytest -v jupyterhub/tests/<test-file-name>::<test-name>
    

    This runs the test with function name <test-name> defined in <test-file-name>. This is very useful when you are iteratively developing a single test.

    For example, to run the test test_shutdown in the file test_api.py, you would run:

    pytest -v jupyterhub/tests/test_api.py::test_shutdown
    

Troubleshooting Test Failures

All the tests are failing

Make sure you have completed all the steps in Setting up a development install successfully, and can launch jupyterhub from the terminal.