tavern


Nametavern JSON
Version 2.10.3 PyPI version JSON
download
home_pageNone
SummarySimple testing of RESTful APIs
upload_time2024-04-13 18:21:57
maintainerNone
docs_urlNone
authorMichael Boulton
requires_python>=3.8
licenseNone
keywords testing pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![pypi](https://img.shields.io/pypi/v/tavern.svg)](https://pypi.org/project/tavern/)
[![docs](https://readthedocs.org/projects/pip/badge/?version=latest&style=flat)](https://tavern.readthedocs.io/en/latest/)
![workflow](https://github.com/taverntesting/tavern/actions/workflows/main.yml/badge.svg?branch=master)

# Easier API testing

Tavern is a pytest plugin, command-line tool and Python library for
automated testing of APIs, with a simple, concise and flexible
YAML-based syntax. It's very simple to get started, and highly
customisable for complex tests. Tavern supports testing RESTful APIs as
well as MQTT based APIs.

The best way to use Tavern is with
[pytest](https://docs.pytest.org/en/latest/). Tavern comes with a
pytest plugin so that literally all you have to do is install pytest and
Tavern, write your tests in `.tavern.yaml` files and run pytest. This
means you get access to all of the pytest ecosystem and allows you to do
all sorts of things like regularly run your tests against a test server
and report failures or generate HTML reports.

You can also integrate Tavern into your own test framework or continuous
integration setup using the Python library, or use the command line
tool, `tavern-ci` with bash scripts and cron jobs.

To learn more, check out the [examples](https://taverntesting.github.io/examples) or the complete
[documentation](https://taverntesting.github.io/documentation). If you're interested in contributing
to the project take a look at the [GitHub
repo](https://github.com/taverntesting/tavern).

## Quickstart

First up run `pip install tavern`.

Then, let's create a basic test, `test_minimal.tavern.yaml`:

```yaml
---
# Every test file has one or more tests...
test_name: Get some fake data from the JSON placeholder API

# ...and each test has one or more stages (e.g. an HTTP request)
stages:
  - name: Make sure we have the right ID

    # Define the request to be made...
    request:
      url: https://jsonplaceholder.typicode.com/posts/1
      method: GET

    # ...and the expected response code and body
    response:
      status_code: 200
      json:
        id: 1
        userId: 1
        title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
        body: "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
```

This file can have any name, but if you intend to use Pytest with
Tavern, it will only pick up files called `test_*.tavern.yaml`.

This can then be run like so:

```bash
$ pip install tavern[pytest]
$ py.test test_minimal.tavern.yaml  -v
=================================== test session starts ===================================
platform linux -- Python 3.5.2, pytest-3.4.2, py-1.5.2, pluggy-0.6.0 -- /home/taverntester/.virtualenvs/tavernexample/bin/python3
cachedir: .pytest_cache
rootdir: /home/taverntester/myproject, inifile:
plugins: tavern-0.7.2
collected 1 item

test_minimal.tavern.yaml::Get some fake data from the JSON placeholder API PASSED   [100%]

================================ 1 passed in 0.14 seconds =================================
```

It is strongly advised that you use Tavern with Pytest - not only does
it have a lot of utility to control discovery and execution of tests,
there are a huge amount of plugins to improve your development
experience. If you absolutely can't use Pytest for some reason, use the
`tavern-ci` command line interface:

```bash
$ pip install tavern
$ tavern-ci --stdout test_minimal.tavern.yaml
2017-11-08 16:17:00,152 [INFO]: (tavern.core:55) Running test : Get some fake data from the JSON placeholder API
2017-11-08 16:17:00,153 [INFO]: (tavern.core:69) Running stage : Make sure we have the right ID
2017-11-08 16:17:00,239 [INFO]: (tavern.core:73) Response: '<Response [200]>' ({
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "json": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
})
2017-11-08 16:17:00,239 [INFO]: (tavern.printer:9) PASSED: Make sure we have the right ID [200]
```

## Why not Postman, Insomnia or pyresttest etc?

Tavern is a focused tool which does one thing well: automated testing of
APIs.

**Postman** and **Insomnia** are excellent tools which cover a wide
range of use-cases for RESTful APIs, and indeed we use Tavern alongside
Postman. However, specifically with regards to automated testing, Tavern
has several advantages over Postman:

- A full-featured Python environment for writing easily reusable custom validation functions
- Testing of MQTT based systems in tandem with RESTful APIS.
- Seamless integration with pytest to keep all your tests in one place
- A simpler, less verbose and clearer testing language

Tavern does not do many of the things Postman and Insomnia do. For
example, Tavern does not have a GUI nor does it do API monitoring or
mock servers. On the other hand, Tavern is free and open-source and is a
more powerful tool for developers to automate tests.

**pyresttest** is a similar tool to Tavern for testing RESTful APIs, but
is no longer actively developed. On top of MQTT testing, Tavern has
several other advantages over PyRestTest which overall add up to a
better developer experience:

- Cleaner test syntax which is more intuitive, especially for
  non-developers
- Validation function are more flexible and easier to use
- Better explanations of why a test failed

## Hacking on Tavern

If you want to add a feature to Tavern or just play around with it
locally, it's a good plan to first create a local development
environment ([this
page](http://docs.python-guide.org/en/latest/dev/virtualenvs/) has a
good primer for working with development environments with Python).
After you've created your development environment, just
`pip install tox` and run `tox` to run the unit tests. If you want
to run the integration tests, make sure you have
[docker](https://www.docker.com/) installed and run
`tox -c tox-integration.ini` (bear in mind this might take a while.)
It's that simple!

If you want to develop things in tavern, enter your virtualenv and run
`pip install -r requirements.txt` to install the library, any requirements,
and other useful development options.

Tavern uses [ruff](https://pypi.org/project/ruff/) to keep all of the code
formatted consistently. There is a pre-commit hook to run `ruff format` which can
be enabled by running `pre-commit install`.

If you want to add a feature to get merged back into mainline Tavern:

- Add the feature you want
- Add some tests for your feature:
    - If you are adding some utility functionality such as improving verification
      of responses, adding some unit tests might be best. These are in the
      `tests/unit/` folder and are written using Pytest.
    - If you are adding more advanced functionality like extra validation
      functions, or some functionality that directly depends on the format of the
      input YAML, it might also be useful to add some integration tests. At the
      time of writing, this is done by adding an example flask endpoint in
      `tests/integration/server.py` and a corresponding Tavern YAML test file in
      the same directory. This will be cleaned up a bit once we have a proper
      plugin system implemented.
- Open a [pull request](https://github.com/taverntesting/tavern/pulls).

See [CONTRIBUTING.md](/CONTRIBUTING.md) for more details.

## Acknowledgements

Tavern makes use of several excellent open-source projects:

- [pytest](https://docs.pytest.org/en/latest/), the testing
  framework Tavern intergrates with
- [requests](http://docs.python-requests.org/en/master/), for HTTP
  requests
- [YAML](http://yaml.org/) and
  [pyyaml](https://github.com/yaml/pyyaml), for the test syntax
- [pykwalify](https://github.com/Grokzen/pykwalify), for YAML schema
  validation
- [pyjwt](https://github.com/jpadilla/pyjwt), for decoding JSON Web
  Tokens
- [colorlog](https://github.com/borntyping/python-colorlog), for
  formatting terminal outputs
- [paho-mqtt](https://github.com/eclipse/paho.mqtt.python), for
  sending MQTT messages

## Maintenance

Tavern is currently maintained by

- @michaelboulton

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tavern",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "testing, pytest",
    "author": "Michael Boulton",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/5d/aa/89203e28d3bca09f9d8ff09fef72b1832b15cb8079df998431b02dfaa369/tavern-2.10.3.tar.gz",
    "platform": null,
    "description": "[![pypi](https://img.shields.io/pypi/v/tavern.svg)](https://pypi.org/project/tavern/)\n[![docs](https://readthedocs.org/projects/pip/badge/?version=latest&style=flat)](https://tavern.readthedocs.io/en/latest/)\n![workflow](https://github.com/taverntesting/tavern/actions/workflows/main.yml/badge.svg?branch=master)\n\n# Easier API testing\n\nTavern is a pytest plugin, command-line tool and Python library for\nautomated testing of APIs, with a simple, concise and flexible\nYAML-based syntax. It's very simple to get started, and highly\ncustomisable for complex tests. Tavern supports testing RESTful APIs as\nwell as MQTT based APIs.\n\nThe best way to use Tavern is with\n[pytest](https://docs.pytest.org/en/latest/). Tavern comes with a\npytest plugin so that literally all you have to do is install pytest and\nTavern, write your tests in `.tavern.yaml` files and run pytest. This\nmeans you get access to all of the pytest ecosystem and allows you to do\nall sorts of things like regularly run your tests against a test server\nand report failures or generate HTML reports.\n\nYou can also integrate Tavern into your own test framework or continuous\nintegration setup using the Python library, or use the command line\ntool, `tavern-ci` with bash scripts and cron jobs.\n\nTo learn more, check out the [examples](https://taverntesting.github.io/examples) or the complete\n[documentation](https://taverntesting.github.io/documentation). If you're interested in contributing\nto the project take a look at the [GitHub\nrepo](https://github.com/taverntesting/tavern).\n\n## Quickstart\n\nFirst up run `pip install tavern`.\n\nThen, let's create a basic test, `test_minimal.tavern.yaml`:\n\n```yaml\n---\n# Every test file has one or more tests...\ntest_name: Get some fake data from the JSON placeholder API\n\n# ...and each test has one or more stages (e.g. an HTTP request)\nstages:\n  - name: Make sure we have the right ID\n\n    # Define the request to be made...\n    request:\n      url: https://jsonplaceholder.typicode.com/posts/1\n      method: GET\n\n    # ...and the expected response code and body\n    response:\n      status_code: 200\n      json:\n        id: 1\n        userId: 1\n        title: \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\"\n        body: \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n```\n\nThis file can have any name, but if you intend to use Pytest with\nTavern, it will only pick up files called `test_*.tavern.yaml`.\n\nThis can then be run like so:\n\n```bash\n$ pip install tavern[pytest]\n$ py.test test_minimal.tavern.yaml  -v\n=================================== test session starts ===================================\nplatform linux -- Python 3.5.2, pytest-3.4.2, py-1.5.2, pluggy-0.6.0 -- /home/taverntester/.virtualenvs/tavernexample/bin/python3\ncachedir: .pytest_cache\nrootdir: /home/taverntester/myproject, inifile:\nplugins: tavern-0.7.2\ncollected 1 item\n\ntest_minimal.tavern.yaml::Get some fake data from the JSON placeholder API PASSED   [100%]\n\n================================ 1 passed in 0.14 seconds =================================\n```\n\nIt is strongly advised that you use Tavern with Pytest - not only does\nit have a lot of utility to control discovery and execution of tests,\nthere are a huge amount of plugins to improve your development\nexperience. If you absolutely can't use Pytest for some reason, use the\n`tavern-ci` command line interface:\n\n```bash\n$ pip install tavern\n$ tavern-ci --stdout test_minimal.tavern.yaml\n2017-11-08 16:17:00,152 [INFO]: (tavern.core:55) Running test : Get some fake data from the JSON placeholder API\n2017-11-08 16:17:00,153 [INFO]: (tavern.core:69) Running stage : Make sure we have the right ID\n2017-11-08 16:17:00,239 [INFO]: (tavern.core:73) Response: '<Response [200]>' ({\n  \"userId\": 1,\n  \"id\": 1,\n  \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n  \"json\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n})\n2017-11-08 16:17:00,239 [INFO]: (tavern.printer:9) PASSED: Make sure we have the right ID [200]\n```\n\n## Why not Postman, Insomnia or pyresttest etc?\n\nTavern is a focused tool which does one thing well: automated testing of\nAPIs.\n\n**Postman** and **Insomnia** are excellent tools which cover a wide\nrange of use-cases for RESTful APIs, and indeed we use Tavern alongside\nPostman. However, specifically with regards to automated testing, Tavern\nhas several advantages over Postman:\n\n- A full-featured Python environment for writing easily reusable custom validation functions\n- Testing of MQTT based systems in tandem with RESTful APIS.\n- Seamless integration with pytest to keep all your tests in one place\n- A simpler, less verbose and clearer testing language\n\nTavern does not do many of the things Postman and Insomnia do. For\nexample, Tavern does not have a GUI nor does it do API monitoring or\nmock servers. On the other hand, Tavern is free and open-source and is a\nmore powerful tool for developers to automate tests.\n\n**pyresttest** is a similar tool to Tavern for testing RESTful APIs, but\nis no longer actively developed. On top of MQTT testing, Tavern has\nseveral other advantages over PyRestTest which overall add up to a\nbetter developer experience:\n\n- Cleaner test syntax which is more intuitive, especially for\n  non-developers\n- Validation function are more flexible and easier to use\n- Better explanations of why a test failed\n\n## Hacking on Tavern\n\nIf you want to add a feature to Tavern or just play around with it\nlocally, it's a good plan to first create a local development\nenvironment ([this\npage](http://docs.python-guide.org/en/latest/dev/virtualenvs/) has a\ngood primer for working with development environments with Python).\nAfter you've created your development environment, just\n`pip install tox` and run `tox` to run the unit tests. If you want\nto run the integration tests, make sure you have\n[docker](https://www.docker.com/) installed and run\n`tox -c tox-integration.ini` (bear in mind this might take a while.)\nIt's that simple!\n\nIf you want to develop things in tavern, enter your virtualenv and run\n`pip install -r requirements.txt` to install the library, any requirements,\nand other useful development options.\n\nTavern uses [ruff](https://pypi.org/project/ruff/) to keep all of the code\nformatted consistently. There is a pre-commit hook to run `ruff format` which can\nbe enabled by running `pre-commit install`.\n\nIf you want to add a feature to get merged back into mainline Tavern:\n\n- Add the feature you want\n- Add some tests for your feature:\n    - If you are adding some utility functionality such as improving verification\n      of responses, adding some unit tests might be best. These are in the\n      `tests/unit/` folder and are written using Pytest.\n    - If you are adding more advanced functionality like extra validation\n      functions, or some functionality that directly depends on the format of the\n      input YAML, it might also be useful to add some integration tests. At the\n      time of writing, this is done by adding an example flask endpoint in\n      `tests/integration/server.py` and a corresponding Tavern YAML test file in\n      the same directory. This will be cleaned up a bit once we have a proper\n      plugin system implemented.\n- Open a [pull request](https://github.com/taverntesting/tavern/pulls).\n\nSee [CONTRIBUTING.md](/CONTRIBUTING.md) for more details.\n\n## Acknowledgements\n\nTavern makes use of several excellent open-source projects:\n\n- [pytest](https://docs.pytest.org/en/latest/), the testing\n  framework Tavern intergrates with\n- [requests](http://docs.python-requests.org/en/master/), for HTTP\n  requests\n- [YAML](http://yaml.org/) and\n  [pyyaml](https://github.com/yaml/pyyaml), for the test syntax\n- [pykwalify](https://github.com/Grokzen/pykwalify), for YAML schema\n  validation\n- [pyjwt](https://github.com/jpadilla/pyjwt), for decoding JSON Web\n  Tokens\n- [colorlog](https://github.com/borntyping/python-colorlog), for\n  formatting terminal outputs\n- [paho-mqtt](https://github.com/eclipse/paho.mqtt.python), for\n  sending MQTT messages\n\n## Maintenance\n\nTavern is currently maintained by\n\n- @michaelboulton\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Simple testing of RESTful APIs",
    "version": "2.10.3",
    "project_urls": {
        "Documentation": "https://tavern.readthedocs.io/en/latest/",
        "Home": "https://taverntesting.github.io/",
        "Source": "https://github.com/taverntesting/tavern"
    },
    "split_keywords": [
        "testing",
        " pytest"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4cc8cbef2d2197a34ba95a7a62c75b9fee5dc606b05cd9d179877beff6629f5a",
                "md5": "2592f9d4ef06a70cda41b01a83db4f1e",
                "sha256": "d72a960ac51cbc9ad91ea741f01eeaf3afd752c8999302082429de4a9e01e8af"
            },
            "downloads": -1,
            "filename": "tavern-2.10.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2592f9d4ef06a70cda41b01a83db4f1e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 105814,
            "upload_time": "2024-04-13T18:21:53",
            "upload_time_iso_8601": "2024-04-13T18:21:53.164265Z",
            "url": "https://files.pythonhosted.org/packages/4c/c8/cbef2d2197a34ba95a7a62c75b9fee5dc606b05cd9d179877beff6629f5a/tavern-2.10.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5daa89203e28d3bca09f9d8ff09fef72b1832b15cb8079df998431b02dfaa369",
                "md5": "54de7003415e579d2286859f64edb189",
                "sha256": "862a150d5ba56c78952c7da1327f86c9cf83b89354416676e419bd6d1fd9fbb2"
            },
            "downloads": -1,
            "filename": "tavern-2.10.3.tar.gz",
            "has_sig": false,
            "md5_digest": "54de7003415e579d2286859f64edb189",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 249337,
            "upload_time": "2024-04-13T18:21:57",
            "upload_time_iso_8601": "2024-04-13T18:21:57.366573Z",
            "url": "https://files.pythonhosted.org/packages/5d/aa/89203e28d3bca09f9d8ff09fef72b1832b15cb8079df998431b02dfaa369/tavern-2.10.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-13 18:21:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "taverntesting",
    "github_project": "tavern",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "tavern"
}
        
Elapsed time: 0.24972s