How can I access st.title in a st.container() with AppTest?

I have this section in streamlit_app.py:

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.

The columns are not inside a container.

Okay… @Goyo
This still doesn’t work:

import streamlit as st

with st.container():
    col1, col = st.columns((1, 1))
    col1.title("My App")

Well, now the columns are inside a container, but they are still accesible in at.columns.

@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.

Weird, both versions of the code pass the test for me.

Really? That’s strange… maybe some dependency issue? What version of Streamlit are you on?

1.28.2

Must have been a dependency issue. I was on 1.28.0 so I deleted the virtual environment and reinstalled everything and now it’s working.