Skip to content

Testing

Kyle Gabriel edited this page Sep 20, 2019 · 8 revisions

How to run all of the tests in test_endpoints.py

  • Attach your virtual environment

source ~/Mycodo/env/activate

  • move into the Mycodo/mycodo directory

cd ~/Mycodo/mycodo

  • call pytest through the python command using the -m flag to set the correct python path (which avoids import errors)
../env/bin/python -m pytest -s tests/software_tests/test_mycodo_flask/test_endpoints.py

============================== test session starts ==============================
platform darwin -- Python 2.7.11, pytest-3.0.3, py-1.4.31, pluggy-0.4.0
rootdir: /Users/username/PycharmProjects/Mycodo/mycodo, inifile: 
collected 7 items 

tests/software_tests/test_mycodo_flask/test_endpoints.py .......

============================== 7 passed in 1.00 seconds ==============================

  • Later have a look at pytest's --help command for more info. The command shown above just tells pytest to run everything in the test_endpoints.py module.

How to run a specific test

  • Move into the Mycodo/mycodo directory with your virtual environment attached
  • Just like the previous command, we call pytest using the python -m command, but this time we use pytest's -k flag to only run tests that match an expression. In this case, let's run the test_user_can_login function.
../env/bin/python -m pytest -s tests/software_tests/test_mycodo_flask/test_endpoints.py -k test_user_can_login

============================== test session starts ==============================
platform darwin -- Python 2.7.11, pytest-3.0.3, py-1.4.31, pluggy-0.4.0
rootdir: /Users/username/PycharmProjects/Mycodo/mycodo, inifile: 
collected 7 items 

tests/software_tests/test_mycodo_flask/test_endpoints.py .

============================== 6 tests deselected ==============================
============================== 1 passed, 6 deselected in 0.73 seconds ==============================