-
Hi, I'm using the User Fixture to test my pages. With NiceGUI 2.24.2, the following setup works well. # pyproject.toml
[project]
name = "nicegui-test"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = [
#"nicegui>3",
"nicegui<3",
"pytest>=8.4.2",
"pytest-asyncio>=1.2.0",
]
[tool.pytest.ini_options]
asyncio_mode = "auto" # main.py
from nicegui import ui
def create_pages():
@ui.page('/')
def main():
ui.label('Hello World!') # conftest.py
import pytest
from nicegui.testing import User
from main import create_pages
pytest_plugins = ["nicegui.testing.user_plugin"]
@pytest.fixture
def user(user: User) -> User:
create_pages()
return user # test_app.py
from nicegui.testing import User
async def test_app(user: User) -> None:
await user.open('/')
await user.should_see('Hello World!') With NiceGUI 3.0.2, I'm getting the following error: ERROR test_app.py::test_app - ValueError: unknown configuration value: 'main_file' I've seen that there is a
I'm getting another error: E RuntimeError:
E
E You must call ui.run() to start the server.
E If ui.run() is behind a main guard
E if __name__ == "__main__":
E remove the guard or replace it with
E if __name__ in {"__main__", "__mp_main__"}:
E to allow for multiprocessing. I'm confused. How am I supposed to use the User Fixture with NiceGUI > 3? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
I'm sorry that it is not working for you out of the box @BayerSe. But I wonder if that is really your complete |
Beta Was this translation helpful? Give feedback.
-
Ah. With 3.0 you do not need to do the separation hack via Delete your Set from nicegui import ui
@ui.page('/')
def main():
ui.label('Hello World!')
def run_dashboard():
ui.run()
if __name__ in {'__main__', '__mp_main__'}:
run_dashboard() In your [project.scripts]
run_dashboard = 'main:run_dashboard' And async def test_app(user: User) -> None:
await user.open('/')
await user.should_see('Hello World!') The [pytest]
asyncio_mode = auto
main_file = main.py
addopts = -p nicegui.testing.plugin |
Beta Was this translation helpful? Give feedback.
-
Thanks, @rodja. I was able to restore my tests.
|
Beta Was this translation helpful? Give feedback.
-
I do not now your code so it might be the simplest solution. But I wonder why show=False etc. is not working in the tests. And if there are things you want to behave different, you can probe for beeing in a pytest execution with |
Beta Was this translation helpful? Give feedback.
-
Oh wow. We should allow that. Can you create a feature request? Looks like it slipped through 😬 |
Beta Was this translation helpful? Give feedback.
-
True. Currently, it can only be changed globally in |
Beta Was this translation helpful? Give feedback.
Ah. With 3.0 you do not need to do the separation hack via
create_pages
anymore. You can keep yourcreate_dashboard
command if you need it. Just make sure thatmain_file
from pytest.ini finds theui.run
. Simplest changes:Delete your
conftest.py
Set
main.py
to:In your
pyproject.toml
:And
test_app.py
:The
pytest.ini
can stay as before: