App testing
Streamlit app testing framework enables developers to build and run headless tests that execute their app code directly, simulate user input, and inspect rendered outputs for correctness.
The provided class, AppTest, simulates a running app and provides methods to set up, manipulate, and inspect the app contents via API instead of a browser UI. It can be used to write automated tests of an app in various scenarios. These can then be run using a tool like pytest. A typical pattern is to build a suite of tests for an app that ensure consistent functionality as the app evolves, and run the tests locally and/or in a CI environment like Github Actions.
The AppTest class
st.testing.v1.AppTest
st.testing.v1.AppTest simulates a running Streamlit app for testing.
AppTest.from_file
st.testing.v1.AppTest.from_file initializes a simulated app from a file.
AppTest.from_string
st.testing.v1.AppTest.from_string initializes a simulated app from a string.
AppTest.from_function
st.testing.v1.AppTest.from_function initializes a simulated app from a function.
Testing-element classes
Block
A representation of container elements, including:
st.chat_messagest.columnsst.sidebarst.tabs- The main body of the app.
Element
The base class for representation of all elements, including:
st.titlest.headerst.markdownst.dataframe
Button
A representation of st.button and st.form_submit_button.
ChatInput
A representation of st.chat_input.
Checkbox
A representation of st.checkbox.
ColorPicker
A representation of st.color_picker.
DateInput
A representation of st.date_input.
Multiselect
A representation of st.multiselect.
NumberInput
A representation of st.number_input.
Radio
A representation of st.radio.
SelectSlider
A representation of st.select_slider.
Selectbox
A representation of st.selectbox.
Slider
A representation of st.slider.
TextArea
A representation of st.text_area.
TextInput
A representation of st.text_input.
TimeInput
A representation of st.time_input.
Toggle
A representation of st.toggle.
Still have questions?
Our forums are full of helpful information and Streamlit experts.