Package: liveandletdie
Live and Let Diesimplifies launching and terminating of web development
servers fromBDDorfunctionaltests. I have created it for functional
testing of theAuthomaticpackage.The package Currently supportsGoogle App engine,Django,Flaskandwsgiref.simple_server. Support for other frameworks will
hopefully be added in future.UsageYou first need to make instance of one of the framework classes.Djangoimportliveandletdie# Djangoapp=liveandletdie.Django('path/to/django/project/',host='0.0.0.0',port=5555)Google App Engineimportliveandletdieapp=liveandletdie.GAE('path/to/dev_appserver.py','path/to/gae/app/dir',# containing app.yaml filehost='0.0.0.0',port=5555)FlaskByFlaskyou must wrap theWSGI applicationinliveandletdie.Flask.wrap(app).If you set thesslkeyword argument toTrue, the app will be run withssl_context="adhoc"and the schema of theself.check_urlwill be"https".NoteIf you are struggling with installation ofpyOpenSSLon OSX due to'ffi.h' file not founderror during installation of thecryptographydependency, try the solution from thisStackoverflow question:$brewinstallpkg-configlibffi$exportPKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/$pipinstallpyopenssl# flask/app/main.pyfromflaskimportFlaskDEBUG=TrueSECRET_KEY='development key'USERNAME='admin'PASSWORD='default'app=Flask(__name__)app.config.from_object(__name__)@app.route('/')defhome():return'Hello World!'if__name__=='__main__':# This does nothing unless you run this module with --liveandletdie flag.importliveandletdieliveandletdie.Flask.wrap(app)app.run()importliveandletdieapp=liveandletdie.Flask('path/to/flask/app/main.py',host='0.0.0.0',port=5555)Pyramid (wsgiref.simple_server)Bywsgiref.simple_serveryou must wrap theWSGI applicationinliveandletdie.WsgirefSimpleServer.wrap(app).If you set thesslkeyword argument toTrue, the app will be run with
a self-signed certificate, and the schema of theself.check_urlwill be"https".# pyramid/app/main.pyfromwsgiref.simple_serverimportmake_serverfrompyramid.configimportConfiguratorfrompyramid.responseimportResponsedefhome(request):returnResponse('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.importliveandletdieliveandletdie.WsgirefSimpleServer.wrap(app)server=make_server('127.0.0.1',8080,app)server.serve_forever()importliveandletdieapp=liveandletdie.Flask('path/to/pyramid/app/main.py',host='0.0.0.0',port=5555)Using the App instanceThe 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 5555process=app.live(kill_port=True)# You can check whether it is runningis_running=app.check()# Stop itapp.die()Simple UnitTest example:https://github.com/peterhudec/liveandletdie/blob/master/test_examples/unittest_example/tests.pySimple PyTest example:https://github.com/peterhudec/liveandletdie/blob/master/test_examples/pytest_example/tests.pySimple Lettuce example:https://github.com/peterhudec/liveandletdie/blob/master/test_examples/lettuce_example/tests.pyDebuggingIf an app refuses to start on theapp.live()call, it throws aLiveAndLetDieErrorwith 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:5555To find out more about why the app didn’t start run the command provided in the
error message manually:$pythonsample_apps/flask/main.py--liveandletdie127.0.0.1:5555DevelopersClone:$ git clone https://github.com/peterhudec/liveandletdie.gitBootstrap the development environment.
This will create the./venvvirtual environment in the project root.$ sh bootstrap.shRun tests:$ sh run-all.shOr bootstrap and run tests in one step:$ sh bootstrap-and-test.shEnjoy!