Skip to main content

Pytest-bravado automatically generates client fixtures from OpenAPI specification. Bravado documentation.

Installation

To install pytest-bravado via pip run the following command:

pip install pytest-bravado

Example Usage

Simple tests:

import pytest

@pytest.mark.parametrize('getUser', [{'id': 1}], indirect=True)
def test_get_user(getUser):
    assert getUser.result


@pytest.mark.parametrize('createUser', [{'id': 2, 'username': 'Ivan'}], indirect=True)
def test_create_user(createUser, getUser):
    assert getUser(id=2).response().result

Support openapi example:

If there is an instance in the specifics, it will be used as the default request body.

parameters:
  - in: "body"
    name: "body"
    schema:
      $ref: "#/definitions/User"
    example:
      id: 10
      username: Oleg
import pytest

def test_create_user(createUser):
    assert createUser.response().result

request body:

{'id': 10, 'username': 'Oleg'}

You can use mark parametrize to change all or part of the example.

@pytest.mark.parametrize('createUser', [{'username': 'Ivan'}], indirect=True)
def test_create_user(createUser):
    assert createUser.result

request body:

{'id': 10, 'username': 'Ivan'}

Run:

pytest --swagger_url http://user-service.com/swagger.json

Spec example:

swagger: "2.0"
info:
  version: "1.0.0"
  title: "User service"
host: "user-service.com"
schemes:
- "http"
paths:
  /user{id}:
    get:
      operationId: "getUser"
      parameters:
      - in: "path"
        name: "id"
        required: true
        type: "integer"
      responses:
        default:
          description: "successful"
          schema:
            $ref: "#/definitions/User"
  /createUser:
    post:
      operationId: "createUser"
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "body"
        schema:
          $ref: "#/definitions/User"
        example:
          id: 10
          username: Oleg
      responses:
        default:
          description: "successful"
definitions:
  User:
    type: "object"
    properties:
      id:
        type: "integer"
      username:
        type: "string"

The following flags are supported

  • –swagger_url - openapi spec url

  • –request_headers - request headers

  • –not_validate_responses - not validate incoming responses

  • –not_validate_requests - not validate outgoing requests

  • –not_validate_swagger_spec - not validate the swagger spec

  • –not_use_models - not use models (Python classes) instead of dicts for #/definitions/{models}

  • –enable_fallback_results - use fallback results even if they’re provided

  • –response_metadata_class - What class to use for response metadata

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-bravado-1.0.10.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_bravado-1.0.10-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest-bravado-1.0.10.tar.gz.

File metadata

  • Download URL: pytest-bravado-1.0.10.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Darwin/18.7.0

File hashes

Hashes for pytest-bravado-1.0.10.tar.gz
Algorithm Hash digest
SHA256 19eda7ca98453d4a200637de7aa0a24a74f8e61d7ff42a69b7677cce9fab0e62
MD5 6ee814878b92481c7786858f74db5d03
BLAKE2b-256 28bcbfaac67268323884a3aff5419d9b76f46766dc5ec2e17ae4200a5b84e74a

See more details on using hashes here.

File details

Details for the file pytest_bravado-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: pytest_bravado-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Darwin/18.7.0

File hashes

Hashes for pytest_bravado-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 bafbe49ff8a1669afbbf35f6c4f2258e28676f49a51e4165134bc6fd2754c7eb
MD5 25a05b10c82b1f6ad73c5804de40b58c
BLAKE2b-256 00dcd91a8410e9d502c2f648c75af0760898fa2704ac04e6677e351a00cb2090

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.10 This release

2 files

1.0.9

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page