taverntesting / tavern

A command-line tool and Python library and Pytest plugin for automated testing of RESTful APIs, with a simple, concise and flexible YAML-based syntax
https://taverntesting.github.io/
MIT License
1.02k stars 193 forks source link

Cleanup Feature request #797

Closed ashishpatel1992 closed 5 months ago

ashishpatel1992 commented 2 years ago

As of now tavern has pytest_tavern_beta_after_every_test_run for performing some task after every test run.

But there can be a option cleanup or some better name for it, in order to perform task when test fails. Something like this

test_name: Get some fake data from the JSON placeholder API

stages:
   - name: Add permission to read user
    request:
      url: https://example.com/add-permission
      method: GET
    response:
      status_code: 200
      save:
        json:
          perm_id: id

  - name: Make sure we have the right ID
    request:
      url: https://example.com/getid/1
      method: GET
    response:
      status_code: 200

  - name: Remove permission to read user
    request:
      url: https://example.com/remove-permission/{perm_id}
      method: GET
    response:
      status_code: 200

cleanup:
    -name : Remove permission
      request: https://example.com/remove-permission/{perm_id}
      method: GET

The above example illustrates why we need cleanup options, so cleanup executes only if test fails in between.

michaelboulton commented 5 months ago

This can now be done using 'finally' blocks: https://tavern.readthedocs.io/en/latest/basics.html#finalising-stages