Skip to content

Commit 063082a

Browse files
chore: add fixture to Streamlit test
1 parent 797e44a commit 063082a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

run/helloworld-streamlit/main_test.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,28 @@
1313
# limitations under the License.
1414

1515
from streamlit.testing.v1 import AppTest
16+
import pytest
1617

17-
def test_balloons():
18-
"""A user presses the balloons button"""
18+
19+
@pytest.fixture
20+
def app_test() -> AppTest:
21+
"""Fixture for creating a test app instance and setting a name."""
1922
at = AppTest.from_file("main.py").run()
2023
at.text_input[0].set_value("Foo").run()
21-
at.button[0].click().run()
22-
assert at.markdown.values[0] == "This is a demo Streamlit app.\n\nEnter your name in the text box below and press a button to see some fun features in Streamlit."
23-
assert at.markdown.values[1] == "Time to celebrate Foo! 🥳"
24-
assert at.markdown.values[2] == "You deployed a Streamlit app! 👏"
24+
return at
25+
26+
27+
def test_balloons(app_test: AppTest):
28+
"""A user presses the balloons button"""
29+
app_test.button[0].click().run()
30+
assert app_test.markdown.values[0] == "This is a demo Streamlit app.\n\nEnter your name in the text box below and press a button to see some fun features in Streamlit."
31+
assert app_test.markdown.values[1] == "Time to celebrate Foo! 🥳"
32+
assert app_test.markdown.values[2] == "You deployed a Streamlit app! 👏"
33+
2534

26-
def test_snow():
35+
def test_snow(app_test: AppTest):
2736
"""A user presses the snow button"""
28-
at = AppTest.from_file("main.py").run()
29-
at.text_input[0].set_value("Foo").run()
30-
at.button[1].click().run()
31-
assert at.markdown.values[0] == "This is a demo Streamlit app.\n\nEnter your name in the text box below and press a button to see some fun features in Streamlit."
32-
assert at.markdown.values[1] == "Let it snow Foo! 🌨️"
33-
assert at.markdown.values[2] == "You deployed a Streamlit app! 👏"
34-
37+
app_test.button[1].click().run()
38+
assert app_test.markdown.values[0] == "This is a demo Streamlit app.\n\nEnter your name in the text box below and press a button to see some fun features in Streamlit."
39+
assert app_test.markdown.values[1] == "Let it snow Foo! 🌨️"
40+
assert app_test.markdown.values[2] == "You deployed a Streamlit app! 👏"

0 commit comments

Comments
 (0)