import streamlit as st
col1, col = st.columns((1, 1))
with st.container():
col1.title("My App")
and I am trying to use AppTest to test that st.title is equal to “My App” but I can’t seem to access it with my test file:
from streamlit.testing.v1 import AppTest
at = AppTest.from_file("graph.py", default_timeout=75).run()
def test_headers():
assert "My App" in at.container[0].columns[0].title[0].value
I can’t seem to find it in the docs on how to access the container. I know there is this section, retrieve containers, but, at least to me, it’s not super clear how to access elements in a container. An example like this in the docs would be nice. The cheatsheet for layouts and containers doesn’t to have an example for containers except for sidebar, columns, and tabs.
@Goyo either way, I can’t seem to get pytest to pass the test so I am still not sure what I am doing wrong and what I need to do.
This passes:
test file:
from streamlit.testing.v1 import AppTest
at = AppTest.from_file("graph.py", default_timeout=75).run()
def test_headers():
assert "My App" in at.columns[0].title[0].value
streamlit file:
import streamlit as st
col1, col2 = st.columns((9, 1))
col1.title("My App")
This fails:
but the moment I put the streamlit file code in a container, it fails:
import streamlit as st
with st.container():
col1, col2 = st.columns((9, 1))
col1.title("My App")
so it doesn’t seem to that they are accessible in at.columns like you mentioned unless I’m missing something.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.