Streamlit live server for testing purposes?

Hi folks,

First, some background info: my organisation has a streamlit webapp using a postgres database. For this database we’re using the Django ORM. We have both a staging and production server. We’ve reached a scale that we really need to implement CI/CD.

In Django there’s a test class named LiveServerTestCase that launches a live Django server in the background on setup. This live server automatically connects to your temporary test database (which is created upon running tests). You can then write your Selenium tests as necessary. I’m hoping that someone knows of an equivalent, or a hacky workaround that we could use in streamlit for this purpose?

My issue thus far is that I cannot launch the streamlit server from within my tests, so I need to separately run the Streamlit server, then run the tests.

The problem then becomes that this already running streamlit server is naturally connected to my local database, not the temporary test database. So the setup data specified in my test cases is not available.
I can likely implement a manual solution with custom setup/teardown methods for our test database, and run streamlit on another process, but before I go along that road I’m hoping there’s an easier way.

If anyone could provide any suggestions it’d be much appreciated.

Regards,

Ruairi

Hi @clintonruairi -

This is how I set up a test environment using GitHub Actions and the blog post that accompanies it:

Hopefully you can do something similar with your infrastructure.

Best,
Randy

1 Like

Thanks Randy, I’ve actually already read your article. Unfortunately I don’t think it’ll work for our purposes, we need to be able to connect our tests to a temporary database which will need to be accessible via a streamlit live server.

I’m not sure I understand the distinction you are making. Can’t you have the credentials for the database passed to the test suite?

I might be over-simplifying, but based on

already running streamlit server is naturally connected to my local database

I’m thinking you could add an environment variable / Streamlit secret for the database connection details? (this example uses pydantic, but the general idea is to load the config from environment)

Otherwise I think “custom setup/teardown methods for our test database” is the way to go, maybe with docker-compose to make networking in CI/CD easier