Py test is python framework that is used for unit testing.
You must have downloaded python and pip pakage manager to install pytest. You can download with this link https://packaging.python.org/en/latest/tutorials/installing-packages/ .Following are the steps to intall pytest.
- Run the following command in your command line:
pip install -U pytest
- Check that you installed the correct version:
pytest --version
- You can run the single test program by following command (here my program name is first_test.py) :
pytest first_test.py
- For multiple test case program you can run using testname bye sub-string maching or group test by marker.
i. For sub-string matching following command is used(for example method1 is my test method) :
here -k used for substring mathc and -v icreases the posiiblilities. ii. Using marker program can be run by command (you have to declare the marker before the test function eg."@pytest.mark.first") :
py.test -k method1 -v
py.test -m one
To use the module requests in api test by pytest, you need to install request else it will so error "ModuleNotFoundError: No module named 'requests'" . To install request you should have install pip. Then hit following command:
pip install requests
Or you can read this stackoverflow solution
https://stackoverflow.com/questions/17309288/importerror-no-module-named-requests