All Projects → AndreyErmilov → pytest-mock-server

AndreyErmilov / pytest-mock-server

Licence: MIT license
Mock server plugin for pytest

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pytest-mock-server

pytest-snail
Plugin for adding a marker to slow running tests. 🐌
Stars: ✭ 15 (-21.05%)
Mutual labels:  pytest, pytest-plugin
pytest-pipeline
Pytest plugin for functional testing of data analysis pipelines
Stars: ✭ 19 (+0%)
Mutual labels:  pytest, pytest-plugin
pytest-datafiles
pytest plugin to create a tmpdir containing a preconfigured set of files and/or directories.
Stars: ✭ 75 (+294.74%)
Mutual labels:  pytest, pytest-plugin
Seleniumbase
A Python framework that inspires developers to become better test automation engineers. 🧠💡
Stars: ✭ 2,520 (+13163.16%)
Mutual labels:  pytest, pytest-plugin
pytest-csv
CSV reporter for pytest.
Stars: ✭ 16 (-15.79%)
Mutual labels:  pytest, pytest-plugin
pytest-neo
Matrix has you...
Stars: ✭ 44 (+131.58%)
Mutual labels:  pytest, pytest-plugin
pytest-dependency
Manage dependencies of tests
Stars: ✭ 113 (+494.74%)
Mutual labels:  pytest, pytest-plugin
pytest-arraydiff
pytest plugin to facilitate comparison of results to a pre-defined reference
Stars: ✭ 12 (-36.84%)
Mutual labels:  pytest, pytest-plugin
pytest-subprocess
Pytest plugin to fake subprocess.
Stars: ✭ 83 (+336.84%)
Mutual labels:  pytest, pytest-plugin
pytest-docker-tools
Opionated helpers for creating py.test fixtures for Docker integration and smoke testing environments
Stars: ✭ 61 (+221.05%)
Mutual labels:  pytest, pytest-plugin
Pudb
Full-screen console debugger for Python
Stars: ✭ 2,267 (+11831.58%)
Mutual labels:  pytest, pytest-plugin
pytest-elk-reporter
A plugin to send pytest test results to ELK stack
Stars: ✭ 17 (-10.53%)
Mutual labels:  pytest, pytest-plugin
pytest-reportlog
Replacement for the --resultlog option, focused in simplicity and extensibility
Stars: ✭ 36 (+89.47%)
Mutual labels:  pytest, pytest-plugin
overhave
Web-framework for BDD: scalable, configurable, easy to use, based on Flask Admin and Pydantic.
Stars: ✭ 61 (+221.05%)
Mutual labels:  pytest, pytest-plugin
pytest-djangoapp
Nice pytest plugin to help you with Django pluggable application testing.
Stars: ✭ 35 (+84.21%)
Mutual labels:  pytest, pytest-plugin
pytest-involve
A pytest plugin to run tests pertaining to a specific file or changeset
Stars: ✭ 28 (+47.37%)
Mutual labels:  pytest, pytest-plugin
pytest-localstack
Pytest plugin for local AWS integration tests
Stars: ✭ 66 (+247.37%)
Mutual labels:  pytest, pytest-plugin
pytest-snapshot
A plugin for snapshot testing with pytest.
Stars: ✭ 68 (+257.89%)
Mutual labels:  pytest, pytest-plugin
pytest-pycodestyle
pytest plugin to run pycodestyle
Stars: ✭ 15 (-21.05%)
Mutual labels:  pytest, pytest-plugin
pytest-datafixtures
Data fixtures for pytest made simple
Stars: ✭ 24 (+26.32%)
Mutual labels:  pytest, pytest-plugin

pytest-mock-server

PyPI version Python versions See Build Status on Travis CI

Mock server plugin for pytest


Installation

You can install "pytest-mock-server" via pip from PyPI:

$ pip install pytest-mock-server

Usage

One handler

import pytest
import requests

@pytest.mark.server(url='/v1/books/', response=[{'id': 1}], method='GET')
def test_handler_responses():
    response = requests.get('http://localhost:5000/v1/books/')
    assert response.status_code == 200
    assert response.json() == [{'id': 1}]

More than one handlers

import pytest
import requests

@pytest.mark.server(url='/v1/books/', response=[{'id': 1}], method='GET')
@pytest.mark.server(url='/v1/books/<book_id>/', response={'id': 1}, method='GET')
def test_handler_responses():
    response = requests.get('http://localhost:5000/v1/books/')
    assert response.status_code == 200
    assert response.json() == [{'id': 1}]
    response = requests.get('http://localhost:5000/v1/books/1/')
    assert response.status_code == 200
    assert response.json() == {'id': 1}

Callback executes before response returns

import pytest
import requests
import time

def sleep_two(*args, **kwargs):
    time.sleep(2)

@pytest.mark.server(url='/v1/books/', response={}, callback=sleep_two)
def test_handler_responses():
    """Ensures Timeouts works"""
    with pytest.raises(requests.exceptions.Timeout):
        response = requests.get('http://localhost:5000/v1/books/', timeout=1)

Custom settings for server

import pytest
import requests

@pytest.mark.server(url='/v1/books/', response={})
@pytest.mark.server_settings(port=8000)
def test_handler_responses():
    response = requests.get('http://localhost:8000/v1/books/')
    assert response.status_code == 200
    assert response.json() == {}

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, "pytest-mock-server" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].