Skip to content

Testing

Kyle Gabriel edited this page Oct 25, 2016 · 8 revisions

How to run all of the tests in test_endpoints.py

  • Attach your virutal environment (mine is called mycodo_py2_venv)
mac:mycodo username$ source ~/PythonVirtualEnvironments/mycodo_py2_venv/bin/activate
(mycodo_py2_venv)mac:mycodo username$ 
  • move into the Mycodo/mycodo directory
(mycodo_py2_venv)mac:Mycodo username$ cd mycodo
  • call pytest through the python command using the -m flag to set the correct python path (which avoids import errors)
(mycodo_py2_venv)mac:mycodo username$ python -m pytest 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 tests

  • 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, lets run the test_user_can_login function.
(mycodo_py2_venv)mac:mycodo username$ python -m pytest 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 ==============================
Clone this wiki locally