Skip to main content

Live and Let Die

https://travis-ci.org/peterhudec/liveandletdie.svg?branch=master

Live and Let Die simplifies launching and terminating of web development servers from BDD or functional tests. I have created it for functional testing of the Authomatic package.

The package Currently supports Google App engine, Django, Flask and wsgiref.simple_server. Support for other frameworks will hopefully be added in future.

Usage

You first need to make instance of one of the framework classes.

Django

import liveandletdie

# Django
app = liveandletdie.Django('path/to/django/project/',
                           host='0.0.0.0',
                           port=5555)

Google App Engine

import liveandletdie

app = liveandletdie.GAE('path/to/dev_appserver.py',
                        'path/to/gae/app/dir', # containing app.yaml file
                        host='0.0.0.0',
                        port=5555)

Flask

By Flask you must wrap the WSGI application in liveandletdie.Flask.wrap(app).

If you set the ssl keyword argument to True, the app will be run with ssl_context="adhoc" and the schema of the self.check_url will be "https".

# flask/app/main.py
from flask import Flask

DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'

app = Flask(__name__)
app.config.from_object(__name__)

@app.route('/')
def home():
    return 'Hello World!'

if __name__ == '__main__':

    # This does nothing unless you run this module with --liveandletdie flag.
    import liveandletdie
    liveandletdie.Flask.wrap(app)

    app.run()
import liveandletdie

app = liveandletdie.Flask('path/to/flask/app/main.py',
                          host='0.0.0.0',
                          port=5555)

Pyramid (wsgiref.simple_server)

By wsgiref.simple_server you must wrap the WSGI application in liveandletdie.WsgirefSimpleServer.wrap(app).

If you set the ssl keyword argument to True, the app will be run with a self-signed certificate, and the schema of the self.check_url will be "https".

# pyramid/app/main.py
from wsgiref.simple_server import make_server

from pyramid.config import Configurator
from pyramid.response import Response


def home(request):
    return Response('Hello World!')


if __name__ == '__main__':

    config = Configurator()
    config.add_route('home', '/')
    config.add_view(home, route_name='home')
    app = config.make_wsgi_app()

    # This does nothing unless you run this module with --liveandletdie flag.
    import liveandletdie
    liveandletdie.WsgirefSimpleServer.wrap(app)

    server = make_server('127.0.0.1', 8080, app)
    server.serve_forever()
import liveandletdie

app = liveandletdie.Flask('path/to/pyramid/app/main.py',
                          host='0.0.0.0',
                          port=5555)

Using the App instance

The interface is the same for all of the supported frameworks.

# Start the app.
# If kill_port is True,
# it will kill any process listening on port 5555
process = app.live(kill_port=True)

# You can check whether it is running
is_running = app.check()

# Stop it
app.die()

Simple UnitTest example: https://github.com/peterhudec/liveandletdie/blob/master/test_examples/unittest_example/tests.py

Simple PyTest example: https://github.com/peterhudec/liveandletdie/blob/master/test_examples/pytest_example/tests.py

Simple Lettuce example: https://github.com/peterhudec/liveandletdie/blob/master/test_examples/lettuce_example/tests.py

Debugging

If an app refuses to start on the app.live() call, it throws a LiveAndLetDieError with a message:

Flask server https://127.0.0.1:5555 didn't start in specified timeout 10.0 seconds!
command: python sample_apps/flask/main.py --liveandletdie 127.0.0.1:5555

To find out more about why the app didn’t start run the command provided in the error message manually:

$ python sample_apps/flask/main.py --liveandletdie 127.0.0.1:5555

Developers

Clone:

$ git clone https://github.com/peterhudec/liveandletdie.git

Bootstrap the development environment. This will create the ./venv virtual environment in the project root.

$ sh bootstrap.sh

Run tests:

$ sh run-all.sh

Or bootstrap and run tests in one step:

$ sh bootstrap-and-test.sh

Enjoy!

Metadata

Release files for liveandletdie 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for liveandletdie 0.0.9
File Size Uploaded Provenance Actions
liveandletdie-0.0.9.tar.gz 19.3 kB Without provenance Details for liveandletdie-0.0.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for liveandletdie 0.0.9
File Interpreter ABI Platform Actions
liveandletdie-0.0.9-py2.py3-none-any.whl Python 2, Python 3 none any Details for liveandletdie-0.0.9-py2.py3-none-any.whl

Total release size: 28.0 kB

Release files / liveandletdie-0.0.9.tar.gz

Download URL liveandletdie-0.0.9.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6c86f8c1654cc5aef33842bf5bc29e5e03876be4edf7ff11e6df80343942b4f9
BLAKE2b-256 checksum
How to use checksums
d4485540ffa2eec03aa3a5e140fd06d8f381841387fcb4797047040600f3d7b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release files / liveandletdie-0.0.9-py2.py3-none-any.whl

Download URL liveandletdie-0.0.9-py2.py3-none-any.whl
Size 8.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bf693a81ea1ffd2de9ae1a5b4fdab05eef1709d9b9fa9350614534ddbff5e861
BLAKE2b-256 checksum
How to use checksums
14fa94e597d17dc526a253d5de5117dcfb3a65da2c32cd93854c543a66e62e7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Security for liveandletdie 0.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page