|
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | 15 | from streamlit.testing.v1 import AppTest |
| 16 | +import pytest |
16 | 17 |
|
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.""" |
19 | 22 | at = AppTest.from_file("main.py").run() |
20 | 23 | 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 | + |
25 | 34 |
|
26 | | -def test_snow(): |
| 35 | +def test_snow(app_test: AppTest): |
27 | 36 | """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