- Notifications
You must be signed in to change notification settings - Fork0
Declarative HTTP Testing for Python and anything else
License
Koalab99/gabbi
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Gabbi is a tool for running HTTP tests where requests and responsesare represented in a declarative YAML-based form. The simplest testlooks like this:
tests:- name: A test GET: /api/resources/id
See thedocs for more details on the many features and formats forsetting request headers and bodies and evaluating responses.
Gabbi is tested with Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 and pypy3.
Tests can be run usingunittest style test runners,pytestor from the command line with agabbi-run script.
There is agabbi-demo repository which provides a tutorial viaits commit history. The demo builds a simple API using gabbi tofacilitate test driven development.
Gabbi works to bridge the gap between human readable YAML files thatrepresent HTTP requests and expected responses and the obscured realm ofPython-based, object-oriented unit tests in the style of the unittestmodule and its derivatives.
Each YAML file represents an ordered list of HTTP requests along withthe expected responses. This allows a single file to represent aprocess in the API being tested. For example:
- Create a resource.
- Retrieve a resource.
- Delete a resource.
- Retrieve a resource again to confirm it is gone.
At the same time it is still possible to ask gabbi to run just onerequest. If it is in a sequence of tests, those tests prior to it inthe YAML file will be run (in order). In any single process any testwill only be run once. Concurrency is handled such that one fileruns in one process.
These features mean that it is possible to create tests that areuseful for both humans (as tools for improving and developing APIs)and automated CI systems.
To get started, after cloning therepository, you should install thedevelopment dependencies:
$ pip install -r requirements-dev.txt
If you prefer to keep things isolated you can create a virtualenvironment:
$ virtualenv gabbi-venv$ . gabbi-venv/bin/activate$ pip install -r requirements-dev.txt
Gabbi is set up to be developed and tested usingtox (installed viarequirements-dev.txt
). To run the built-in tests (the YAML filesare in the directoriesgabbi/tests/gabbits_*
and loaded by the filegabbi/test_*.py
), you calltox
:
tox -epep8,py37
If you have the dependencies installed (or a warmed upvirtualenv) you can run the tests by hand and exit on the firstfailure:
python -m subunit.run discover -f gabbi | subunit2pyunit
Testing can be limited to individual modules by specifying themafter the tox invocation:
tox -epep8,py37 -- test_driver test_handlers
If you wish to avoid running tests that connect to internet hosts,setGABBI_SKIP_NETWORK
toTrue
.