This application is built to do REST API testing using python scripts along with the use of Pytest module as our testing framework.
Above Features are used to make code simple, generic, understandable, clean and easily maintainable for future development.
Install the dependencies and start the testing.
Install Pytest:
pip3 install --user -U pytestInstall Requests:
pip3 install --user requestsInstall Json Path:
pip3 install --user jsonpathTo run a test, you can simply write the following command on Terminal:
pytestTo run and get details of all the executed test, you can simply write the following command on Terminal:
pytest -rATo run and generate full HTML details report of all the executed test, you can simply write the following commands on Terminal:
But first install Pytest-HTML by writing the following command on Terminal
pip3 install --user pytest-htmlThen write the following command on Terminal
pytest --html=YOUR_REPORT_FILE_NAME.htmlTo see the reports, open the Project window, and then right-click then click on refresh then right-click on StationReport.html to open the file on the default browser.
A minimal example using the HTTP layer to fetch station data:
from session import HTTPSession, RequestTypes, Endpoints
params = {"latMin": 60.164101, "latMax": 60.164104, "longMin": 24, "longMax": 25}
status_code, data = HTTPSession.send_request(RequestTypes.GET, Endpoints.STATIONS, params)
print(status_code, type(data)) # e.g., '200', <class 'list'>Notes:
- The
do_loggingflag inparamscontrols request logging. It defaults toTrue. Set{"do_logging": False}to skip logging. - On
requestsexceptions,send_requestreturnsNone.
- Logs are written to the console and appended to
tests_output.login the repository root. - Tests mock logging to avoid file I/O during runs.
- There is no rotation; the file grows over time. Delete it if it becomes too large.
StatusCodes.STATUS_200is'200'(a string). The customassert_equalcompares stringified values by default to avoid type fragility.- For strict type comparisons, pass
compare_types=Truetoassert_equal.
If pytest has trouble collecting tests, try targeting the file or specific tests directly:
python3 -m pytest -q tests/test_stations.py
python3 -m pytest -q -k test_send_request_handles_request_exception_and_returns_none
python3 -m pytest -vv- Prefer behavior-focused tests that mock external effects (network, file I/O).
- Patch
session.requests.getandsession.Logger.log_requestin tests to ensure determinism and isolation. - Keep tests small and readable; avoid mocking internal implementation details unnecessarily.
- Use the provided constants in
test_utils.pyfor station schema expectations.
This project references the Apache-2.0 license. Ensure a LICENSE file is present or review the badge link for details:
- Python
- Any IDE

