Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.storage.user in unit tests throws error. #2956

Closed
JanHaegdorensPXL opened this issue Apr 25, 2024 · 1 comment
Closed

app.storage.user in unit tests throws error. #2956

JanHaegdorensPXL opened this issue Apr 25, 2024 · 1 comment

Comments

@JanHaegdorensPXL
Copy link

JanHaegdorensPXL commented Apr 25, 2024

Description

When i try to acces app.storage.user in my testcode It throws an error. Even though I added the storage secret inside UI.run and my testscode by using screen.ui_run_kwargs['storage_secret'] = "123".

raise RuntimeError('app.storage.user needs a storage_secret passed in ui.run()')

gui.py

@ui.page("/")
@ui.page("/training")
def training_page():
    Training()

if __name__ in {"__main__", "__mp_main__"}:
    ui.run(port=7000, storage_secret="123")

TrainingTests.py

from nicegui import app, ui
from nicegui.testing import Screen

def test_withscreen(screen: Screen):
    from GUI.gui import training_page
    screen.ui_run_kwargs['storage_secret'] = "123"
    screen.open("/training")

    app.storage.user['count'] = app.storage.user.get('count', 0) + 1
@JanHaegdorensPXL JanHaegdorensPXL changed the title Storage.user in unit tests throws error. app.storage.user in unit tests throws error. Apr 25, 2024
@falkoschindler
Copy link
Contributor

Hi @JanHaegdorensPXL,

I guess you're trying to access the user storage from within the pytest thread, which doesn't work.
We usually test for UI element that depend on stored values. Alternatively you can read the storage files like we do in test_storage.py:
https://github.com/zauberzeug/nicegui/blob/main/tests/test_storage.py

@falkoschindler falkoschindler closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants