Skip to content

Commit

Permalink
Improved end2end test typing
Browse files Browse the repository at this point in the history
- tighten the mypy thumbscrews
- fixed the mypy errors

Change-Id: Ibb0a586804074258d44f33c7994a92f1fafbee0f
  • Loading branch information
Maximilian Wirtz committed May 12, 2022
1 parent 2bd435a commit 605a2ad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mypy-raw.ini
Expand Up @@ -5,7 +5,7 @@
ignore_missing_imports = True

# This should be kept in sync with the pyproject.toml section
[mypy-cmk.notification_plugins.*]
[mypy-cmk.notification_plugins.*,tests.gui_e2e.*,tests.testlib.playwright.*]
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Expand Up @@ -38,7 +38,9 @@ target-version = ['py39']
# If you add more modules, add them to mypy-raw.ini as well...
[[tool.mypy.overrides]]
module = [
"cmk.notification_plugins.*"
"cmk.notification_plugins.*",
"tests.gui_e2e.*",
"tests.testlib.playwright.*"
]
disallow_untyped_calls = true
disallow_untyped_defs = true
Expand Down
8 changes: 4 additions & 4 deletions tests/testlib/playwright/plugin.py
Expand Up @@ -55,7 +55,7 @@ def _playwright() -> t.Generator[Playwright, None, None]:

@pytest.fixture(scope="session", name="browser_type")
def _browser_type(playwright: Playwright, browser_name: str) -> BrowserType:
return getattr(playwright, browser_name)
return t.cast(BrowserType, getattr(playwright, browser_name))


@pytest.fixture(scope="session", name="browser")
Expand Down Expand Up @@ -87,7 +87,7 @@ def _may_create_screenshot(
request: pytest.FixtureRequest,
pytestconfig: t.Any,
pages: t.List[Page],
):
) -> None:
failed = request.node.rep_call.failed if hasattr(request.node, "rep_call") else True
screenshot_option = pytestconfig.getoption("--screenshot")
capture_screenshot = screenshot_option == "on" or (
Expand Down Expand Up @@ -131,8 +131,8 @@ def is_chromium(browser_name: str) -> bool:


@pytest.fixture(name="browser_name", scope="session")
def _browser_name(pytestconfig: t.Any) -> t.Optional[str]:
browser_names = pytestconfig.getoption("--browser")
def _browser_name(pytestconfig: t.Any) -> str:
browser_names = t.cast(list[str], pytestconfig.getoption("--browser"))
if len(browser_names) == 0:
return "chromium"
if len(browser_names) == 1:
Expand Down
10 changes: 7 additions & 3 deletions tests/testlib/playwright/timeouts.py
Expand Up @@ -5,6 +5,8 @@

""" definitions of timeouts during e2e testing
"""
from types import TracebackType
from typing import Type

from playwright.sync_api import Page

Expand All @@ -18,12 +20,14 @@ class TemporaryTimeout:

default_timeout_ms = 30000

def __init__(self, page: Page, temporary_timeout_ms: int):
def __init__(self, page: Page, temporary_timeout_ms: int) -> None:
self.page = page
self.timeout = temporary_timeout_ms

def __enter__(self):
def __enter__(self) -> None:
self.page.set_default_timeout(self.timeout)

def __exit__(self, exc_type, exc_value, exc_tb):
def __exit__(
self, exc_type: Type[BaseException], exc_value: BaseException, exc_tb: TracebackType
) -> None:
self.page.set_default_timeout(self.default_timeout_ms)

0 comments on commit 605a2ad

Please sign in to comment.