My entry file is the 0_X_Home.py (where X is the emoji). Iโm importing my local utils package for added functionality. Here, Iโm using the set_state module:
The app works fine locally using streamlit run 0_X_Home.py, but when I create the test file test_home.py and use AppTest.from_file and point to the entry file, it gives the following error when I run pytest.
2023-11-20 11:57:23.824 Uncaught app exception
Traceback (most recent call last):
File "/home/ezra/.cache/pypoetry/virtualenvs/az-streamlit-qhVRzfSP-py3.10/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
exec(code, module.__dict__)
File "/home/ezra/az-streamlit/az_streamlit/0_๐ _Home.py", line 2, in <module>
from utils import set_state
ModuleNotFoundError: No module named 'utils'
Iโve checked out some example apps but canโt figure out where Iโm going wrong.
Thanks for taking a look. Iโve tried a few different setups.
From ~/az-streamlit/az_streamlit I run either poetry run pytest or poetry run pytest test_home.py, in both cases I get the same error:
=============================================================================== FAILURES ================================================================================
__________________________________________________________________________ test_set_study_code __________________________________________________________________________
def test_set_study_code():
at = AppTest.from_file("0_๐ _Home.py").run()
> assert not at.exception
E assert not ElementList(_list=[Exception(message="No module named 'utils'", stack_trace=['File "/home/ezra/.cache/pypoetry/virtual...)', 'File "/home/ezra/az-streamlit/az_streamlit/0_๐ _Home.py", line 2, in <module>\n from utils import set_state'])])
E + where ElementList(_list=[Exception(message="No module named 'utils'", stack_trace=['File "/home/ezra/.cache/pypoetry/virtual...)', 'File "/home/ezra/az-streamlit/az_streamlit/0_๐ _Home.py", line 2, in <module>\n from utils import set_state'])]) = AppTest(_script_path='0_๐ _Home.py', default_timeout=3, session_state={$$STREAMLIT_INTERNAL_KEY_SCRIPT_RUN_WITHOUT_ERRO... 2, in <module>\n from utils import set_state'])}), 1: SpecialBlock(type='sidebar'), 2: SpecialBlock(type='event')}).exception
test_home.py:5: AssertionError
------------------------------------------------------------------------- Captured stderr call --------------------------------------------------------------------------
2023-11-20 12:26:53.249 Uncaught app exception
Traceback (most recent call last):
File "/home/ezra/.cache/pypoetry/virtualenvs/az-streamlit-qhVRzfSP-py3.10/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
exec(code, module.__dict__)
File "/home/ezra/az-streamlit/az_streamlit/0_๐ _Home.py", line 2, in <module>
from utils import set_state
ModuleNotFoundError: No module named 'utils'
======================================================================== short test summary info ========================================================================
FAILED test_home.py::test_set_study_code - assert not ElementList(_list=[Exception(message="No module named 'utils'", stack_trace=['File "/home/ezra/.cache/pypoetry/virtual...)', 'File "/home/ezra/az-streaml...
FYI
'''test_home.py contents'''
from streamlit.testing.v1 import AppTest
def test_set_study_code():
at = AppTest.from_file("0_๐ _Home.py").run()
assert not at.exception
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.