Using Python Agent - Running backend server using SeaLights agent

In order to capture code coverage on your backend server, you need to run it using our Python test listener agent. Below you’ll find several options depending on your server type.

The below commands assume the token and session id are located in the working directory. If not, you can provide the file locations using the sl.tokenFile and sl.buildSessionIdFile environment variables

uWSGI

When working with uWSGI, you need to run it with the following flags either in the command line or in the uwsgi configuration file: --enable-threads  --single-interpreter --lazy-apps --import python_agent.init

If you need to pass the parameters via the CLI, the command line will be similar to this

uwsgi ... --enable-threads  --single-interpreter --import python_agent.init

If using the uWSGI config file option, the content should look like the sample below

[uwsgi] ... enable-threads = true single-interpreter = true import = python_agent.init

Gunicorn WSGI

When working with Gunicorn WSGI you need to run it with the following a configuration file which contains an import of the SeaLights Python agent in the post_fork section

... def post_fork(server, worker): import python_agent.init ...

Uvicorn ASGI

Uvicorn does not support importing module to be run before the app is started (as in uwsgi).
in order to overcome this there is a code change need to be done at the source code in order to init Sealights when Uvicorn is loading

Running the app:

Other servers (Generic solution)

For other servers, run with the SeaLights Python agent and the run flags

The first parameter after the run command should be an executable file