Feedback wanted for Streamlit App Testing

Hey community, :wave:

We’re currently working on an app testing framework and would love your feedback! This will make it dramatically easier to build automated tests for your app.

You can explore the feature here in the Codespaces demo.

Would love to know:

  • How you would use this feature
  • What you think of this approach
  • If you would use this when building a future Streamlit app

Read here for more info and see a walkthrough from @jcarroll in this video!

Looking forward to hearing what you think. :balloon:

5 Likes

Extremely good feature. Looking forward to see an interface for auto deployment of applications such as st.deploy(github_config=“…”, file=“…”, branch=“…”)

When do you plan to put it into original release that we can use via pip install streamlit?

Hi! As of today you can do pip install streamlit-nightly and the latest version will have the feature as described.

We are hoping to have it fully launched in the next release, but trying it out now and giving feedback will help make that more likely! Thank you!!

Thank you, i will definetely try out.
Any plan for deployment api like st.deploy?

Thanks :slight_smile: Yeah we are looking at making programmatic deploy easier but I’m not sure about the timeline. I think we have discussed it more as happening through the CLI (like “streamlit deploy” similar to “streamlit run”) rather than through a new python API.

3 Likes

Hi @jcarroll really interested in trying this.

We want to improve the automation of our test harnesses and are currently using pytest (experimenting with Selenium). However, if we can use a native streamlit test suite and integrate that with our CICD (in my case via GitHub actions) then all the better!

Super looking forward to the stable production release of this test suite :+1:

1 Like

Hi @jcarroll !

I’m very exciting for this new feature.
It allows me to test streamlit application easily with pytest.

I’d like to share one of our use case, that in this time, we can’t test by this feature.

In our use case , to get who access application now, I create function in which I get header of WSS, like bellow.

_streamlit_version = re.search("(.+\..+)\..+",st.__version__).groups()[0] # 1.11.0 -> 1.11
if  _streamlit_version <= "1.11": # streamkit version 1.11以前
    from streamlit.server.server import Server
    def _get_websocket_headers():
        session_id = st.scriptrunner.get_script_run_ctx().session_id
        session_info = Server.get_current()._session_info_by_id[session_id]
        header = session_info.ws.request.headers
        return header
elif _streamlit_version >= "1.14": # streamkit version 1.14以降
    from streamlit.web.server.websocket_headers import _get_websocket_headers 
else:
    raise ImportError(f"Streamlit version:{st.__version__}は未対応です。")

※I understand this is very hackable way, but at now , there are no solucation to get user name in OSS streamlit ,like st.user in SiS or Community Cloud.

I’ll be very glad this feature support WSS, or achirve testable way to get user name.

When I tried this compnent, I met following error.
Runtime error :session client is not BrowserWebSocketHandler

1 Like

Thank you @katsutoshi.ttm for the great feedback. I heard recently from a few people who are using this headers function so I want to look into whether we can add better explicit support, which would make it easier to test as well.

Just curious, is it possible to work around it with a mock patch, until we have a better solution? Something like this:

from unittest.mock import patch

@patch("streamlit.web.server.websocket_headers._get_websocket_headers")
def test_my_app(headers):
    headers.return_value = {"USER-ID":"my-user"}
    # ...

This seems good work around!
Thanks you @jcarroll , I’ll try it!

Thanks for this new App Test feature, really cool.

Is there a way to interact with st.file_uploader? Or a workaround ? I have an app where users need to upload a file and the if the content of the file is valid, a button will appear so they can do other stuff.

Thanks

Hey @TheDigitilizer , I was playing around with this and trying to figure out if it’s possible. You can inspect that the widget renders and see some of the metadata settings by doing e.g.

fu = at.get("file_uploader")[0]
assert fu is not None
print(fu.proto) # inspect some properties

As best I can tell, there isn’t a way to set the value to a file with what we expose currently. Going to confirm with @AnOctopus. If that’s the case, will see if we can prioritize adding it before too long. Thanks!

1 Like

Thank you for the follow-up, it would be great if you could prioritize the file_uploader :slight_smile:

Hi all, in case you are interested, we recently shipped a small GitHub Action to make it even easier to add tests to your apps and run them automatically.

I shared about it here: Launched: GitHub Action for fast Streamlit app testing