There are a ton of ways to test APIs in python. What I am suggesting here is correct and what I think think the most intuitive python combo to use.
There are three important libraries we are going to leverage:
- pytest :: this is a test
framework that makes it easy to write tests. pytest will run any
function in
tests/test_*.pywith a name that starts withtest_*. - request a great default choice for alibrary to make HTTP/REST API requests.
- yarl a library I'm quite fond of that makes writing api urls easier to construct.
Install python requirements
pip install -r requirements.txtRun the tests. Make sure you are running the command in the root of the repository.
pytestNow make some modifications to tests/test_api.py and run pytest
again to watch tests run. Some useful options to know with pytest.
pytest # normal usage
pytest -s # show all print statements output within tests
pytest -x # stop the tests on the first one that failsAny commit that you make back to the github repo will automatically trigger github-actions (CI) to run the tests.