An open API service indexing awesome lists of open source software.

https://github.com/pomponchik/flask_fixture

Start and stop the flask server for your tests
https://github.com/pomponchik/flask_fixture

fixtures flask pytest pytest-plugin server testing

Last synced: 7 months ago
JSON representation

Start and stop the flask server for your tests

Awesome Lists containing this project

README

          

![logo](https://raw.githubusercontent.com/pomponchik/flask_fixture/main/docs/assets/logo_5.png)

[![Downloads](https://static.pepy.tech/badge/flask_fixture/month)](https://pepy.tech/project/flask_fixture)
[![Downloads](https://static.pepy.tech/badge/flask_fixture)](https://pepy.tech/project/flask_fixture)
[![codecov](https://codecov.io/gh/pomponchik/flask_fixture/graph/badge.svg?token=8iyMsUaLvN)](https://codecov.io/gh/pomponchik/flask_fixture)
[![Hits-of-Code](https://hitsofcode.com/github/pomponchik/flask_fixture?branch=main)](https://hitsofcode.com/github/pomponchik/flask_fixture/view?branch=main)
[![Tests](https://github.com/pomponchik/flask_fixture/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/flask_fixture/actions/workflows/tests_and_coverage.yml)
[![Python versions](https://img.shields.io/pypi/pyversions/flask_fixture.svg)](https://pypi.python.org/pypi/flask_fixture)
[![PyPI version](https://badge.fury.io/py/flask_fixture.svg)](https://badge.fury.io/py/flask_fixture)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

A simple plugin for [Pytest](https://docs.pytest.org/) containing a [fixture](https://docs.pytest.org/explanation/fixtures.html) that can start and stop the [Flask server](https://flask.palletsprojects.com/server/) to run related tests. You just have to define the [routes](https://flask.palletsprojects.com/quickstart/#routing).

Install it by the command:

```bash
pip install flask_fixture
```

Define some routes in your `conftest.py` file:

```python
from flask_fixture import endpoint

@endpoint('/')
def root():
return 'some text'
```

And use a URL of a server in your tests as a fixture `local_server_url`:

```python
import requests

def test_server(local_server_url):
assert requests.get(local_server_url).text == 'some text'
```

The example uses the [Requests](https://requests.readthedocs.io/en/latest/) library.