Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/j-sephb-lt-n/run-local-flask-app-in-background
Code illustrating how to locally host a Flask app in the background (e.g. for automated endpoint testing)
https://github.com/j-sephb-lt-n/run-local-flask-app-in-background
Last synced: about 23 hours ago
JSON representation
Code illustrating how to locally host a Flask app in the background (e.g. for automated endpoint testing)
- Host: GitHub
- URL: https://github.com/j-sephb-lt-n/run-local-flask-app-in-background
- Owner: J-sephB-lt-n
- License: gpl-3.0
- Created: 2024-03-06T09:14:26.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-03-06T09:39:49.000Z (8 months ago)
- Last Synced: 2024-04-17T22:57:31.385Z (7 months ago)
- Language: Python
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# run-local-flask-app-in-background
Code illustrating how to locally host a Flask app in the background (e.g. for automated endpoint testing)```bash
$ pip install -r requirements.txt
``````python
# main.py
import requests
from background_localhost import BackgroundLocalHostwith BackgroundLocalHost(app_name="test_app", port=8000):
endpoint_response = requests.get("http://localhost:5000/health_check")
print(endpoint_response, endpoint_response.text)# check that the background flask app has been killed correctly by the context manager #
try:
endpoint_response = requests.get("http://localhost:8000/health_check")
print(endpoint_response, endpoint_response.text)
except requests.exceptions.ConnectionError:
print("ERROR: cannot connect to http://localhost:8000/health_check")
``````bash
$ python main.py
hosting local flask app 'test_app' on port 8000
127.0.0.1 - "GET /health_check HTTP/1.1" 200 -
Endpoint is working
killed local flask app 'test_app' on port 8000
ERROR: cannot connect to http://localhost:8000/health_check
```