Skip to content

Commit 76dcce2

Browse files
Pytests can load a main file with runpy (#5102)
### Motivation With the introduction of the root page concept, we need to rethink our pytest infrastructure (he `module_under_test` marker and the modular setup with a startup function) ### Implementation `main.py` is loaded via `runpy.run_path` in the fixture setup. ### Progress - [x] I chose a meaningful title that completes the sentence: "If applied, this PR will..." - [x] The implementation is complete. - [x] Pytests have been added. - [x] Documentation has been updated. --------- Co-authored-by: Falko Schindler <[email protected]>
1 parent 108995c commit 76dcce2

29 files changed

+183
-312
lines changed

examples/authentication/__init__.py

Whitespace-only changes.

examples/authentication/conftest.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/authentication/pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
asyncio_mode = auto
3+
main_file = main.py
4+
addopts = -p nicegui.testing.plugin

examples/authentication/test_authentication.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import pytest
2-
31
from nicegui.testing import User
42

5-
from . import main
6-
73
# pylint: disable=missing-function-docstring
84

95

10-
@pytest.mark.module_under_test(main)
116
async def test_login_logoff(user: User) -> None:
127
await user.open('/')
138
user.find('Username').type('user1')
@@ -18,15 +13,13 @@ async def test_login_logoff(user: User) -> None:
1813
await user.should_see('Log in')
1914

2015

21-
@pytest.mark.module_under_test(main)
2216
async def test_wrong_password(user: User) -> None:
2317
await user.open('/')
2418
user.find('Username').type('user1')
2519
user.find('Password').type('wrong').trigger('keydown.enter')
2620
await user.should_see('Wrong username or password')
2721

2822

29-
@pytest.mark.module_under_test(main)
3023
async def test_subpage_access(user: User) -> None:
3124
await user.open('/subpage')
3225
await user.should_see('Log in')

examples/chat_app/__init__.py

Whitespace-only changes.

examples/chat_app/conftest.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/chat_app/pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
asyncio_mode = auto
3+
main_file = main.py
4+
addopts = -p nicegui.testing.plugin

examples/chat_app/test_chat_app.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
from typing import Callable
22

3-
import pytest
4-
53
from nicegui import ui
64
from nicegui.testing import User
75

8-
from . import main
9-
106

11-
@pytest.mark.module_under_test(main)
127
async def test_basic_startup_appearance(user: User) -> None:
138
"""Test basic appearance of the chat app."""
149
await user.open('/')
@@ -18,7 +13,6 @@ async def test_basic_startup_appearance(user: User) -> None:
1813
await user.should_see('No messages yet')
1914

2015

21-
@pytest.mark.module_under_test(main)
2216
async def test_sending_messages(create_user: Callable[[], User]) -> None:
2317
"""Test sending messages from two different screens."""
2418
userA = create_user()

examples/pytests/pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[pytest]
22
asyncio_mode = auto
3+
main_file = main.py
4+
addopts = -p nicegui.testing.plugin

examples/pytests/tests/conftest.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)