diff --git a/py/conftest.py b/py/conftest.py index 5ce71b91182c9..71d7103bbb045 100644 --- a/py/conftest.py +++ b/py/conftest.py @@ -20,13 +20,13 @@ import socket import subprocess import time -from test.selenium.webdriver.common.network import get_lan_ip -from test.selenium.webdriver.common.webserver import SimpleWebServer from urllib.request import urlopen import pytest from selenium import webdriver +from test.selenium.webdriver.common.network import get_lan_ip +from test.selenium.webdriver.common.webserver import SimpleWebServer drivers = ( "chrome", @@ -97,7 +97,7 @@ def pytest_ignore_collect(path, config): def get_driver_class(driver_option): - """Generate the driver class name from the lowercase driver option""" + """Generate the driver class name from the lowercase driver option.""" if driver_option == "webkitgtk": driver_class = "WebKitGTK" elif driver_option == "wpewebkit": @@ -113,10 +113,8 @@ def get_driver_class(driver_option): @pytest.fixture(scope="function") def driver(request): kwargs = {} - # browser can be changed with `--driver=firefox` as an argument or to addopts in pytest.ini driver_class = get_driver_class(getattr(request, "param", "Chrome")) - # skip tests if not available on the platform _platform = platform.system() if driver_class == "Safari" and _platform != "Darwin": @@ -125,12 +123,10 @@ def driver(request): pytest.skip("IE and EdgeHTML Tests can only run on Windows") if "WebKit" in driver_class and _platform == "Windows": pytest.skip("WebKit tests cannot be run on Windows") - # skip tests for drivers that don't support BiDi when --bidi is enabled if request.config.option.bidi: if driver_class in ("Ie", "Safari", "WebKitGTK", "WPEWebKit"): pytest.skip(f"{driver_class} does not support BiDi") - # conditionally mark tests as expected to fail based on driver marker = request.node.get_closest_marker(f"xfail_{driver_class.lower()}") @@ -182,7 +178,6 @@ def fin(): driver_instance = getattr(webdriver, driver_class)(**kwargs) yield driver_instance - # Close the browser after BiDi tests. Those make event subscriptions # and doesn't seems to be stable enough, causing the flakiness of the # subsequent tests. diff --git a/py/pyproject.toml b/py/pyproject.toml index 16b03e241b975..5803c4de29092 100644 --- a/py/pyproject.toml +++ b/py/pyproject.toml @@ -136,15 +136,36 @@ ignore_missing_imports = true # Automatically keep imports alphabetically sorted, on single lines in # PEP recommended sections (https://peps.python.org/pep-0008/#imports) # files or individual lines can be ignored via `# isort:skip|# isort:skip_file`. -profile = "black" -py_version=39 force_single_line = true +profile = "black" +py_version = 39 +quiet = true +skip = "selenium/webdriver/common/devtools" [tool.black] -extend-exclude = 'selenium/webdriver/common/devtools' +extend-exclude = "selenium/webdriver/common/devtools" line-length = 120 -target-version = ['py39'] +target-version = ["py39"] + +[tool.autoflake] +exclude = "selenium/webdriver/common/devtools" +ignore-pass-after-docstring = true +in-place = true +quiet = true +recursive = true +remove-all-unused-imports = true +remove-duplicate-keys = true +remove-unused-variables = true + +[tool.flake8] +exclude = "selenium/webdriver/common/devtools" +# Disable E501 once line length is better handled +extend-ignore = ["E501", "E203"] +# This does nothing for now as E501 is ignored +max-line-length = 120 +min-python-version = "3.9" [tool.docformatter] -exclude = 'selenium/webdriver/common/devtools' +exclude = "selenium/webdriver/common/devtools" +in-place = true recursive = true diff --git a/py/selenium/webdriver/support/expected_conditions.py b/py/selenium/webdriver/support/expected_conditions.py index fd3c81f5f58a6..99fcf7ad571eb 100644 --- a/py/selenium/webdriver/support/expected_conditions.py +++ b/py/selenium/webdriver/support/expected_conditions.py @@ -195,7 +195,7 @@ def _predicate(driver: WebDriver): def visibility_of_element_located( - locator: Tuple[str, str] + locator: Tuple[str, str], ) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]: """An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed @@ -337,7 +337,7 @@ def _predicate(driver: WebDriverOrWebElement): def visibility_of_all_elements_located( - locator: Tuple[str, str] + locator: Tuple[str, str], ) -> Callable[[WebDriverOrWebElement], Union[List[WebElement], Literal[False]]]: """An expectation for checking that all elements are present on the DOM of a page and visible. Visibility means that the elements are not only @@ -486,7 +486,7 @@ def _predicate(driver: WebDriverOrWebElement): def frame_to_be_available_and_switch_to_it( - locator: Union[Tuple[str, str], str, WebElement] + locator: Union[Tuple[str, str], str, WebElement], ) -> Callable[[WebDriver], bool]: """An expectation for checking whether the given frame is available to switch to. @@ -527,7 +527,7 @@ def _predicate(driver: WebDriver): def invisibility_of_element_located( - locator: Union[WebElement, Tuple[str, str]] + locator: Union[WebElement, Tuple[str, str]], ) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]: """An Expectation for checking that an element is either invisible or not present on the DOM. @@ -576,7 +576,7 @@ def _predicate(driver: WebDriverOrWebElement): def invisibility_of_element( - element: Union[WebElement, Tuple[str, str]] + element: Union[WebElement, Tuple[str, str]], ) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]: """An Expectation for checking that an element is either invisible or not present on the DOM. @@ -602,7 +602,7 @@ def invisibility_of_element( def element_to_be_clickable( - mark: Union[WebElement, Tuple[str, str]] + mark: Union[WebElement, Tuple[str, str]], ) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]: """An Expectation for checking an element is visible and enabled such that you can click it. diff --git a/py/tox.ini b/py/tox.ini index 2d3cc9134d894..7bf3bc7dbcdf9 100644 --- a/py/tox.ini +++ b/py/tox.ini @@ -4,8 +4,8 @@ envlist = docs, flake8, isort, validate-pyproject [testenv:validate-pyproject] skip_install = true deps = - validate-pyproject==0.23 - packaging==24.2 + validate-pyproject==0.24.1 + packaging==25.0 commands = validate-pyproject ./pyproject.toml @@ -33,42 +33,45 @@ deps = commands = mypy --install-types {posargs} [testenv:linting-ci] -; checks linting for CI with stricter exiting when failing. +; checks linting for CI with stricter exiting when failing and no rewriting skip_install = true deps = - isort==5.13.2 - black==24.1.1 - flake8==6.1.0 - flake8-typing-imports==1.14.0 + isort==6.0.1 + black==25.1.0 + autoflake==2.3.1 + flake8==7.1.2 + flake8-pyproject==1.2.3 + flake8-typing-imports==1.16.0 docformatter==1.7.5 commands = - ; execute isort in check only mode. isort --check-only --diff selenium/ test/ conftest.py - ; execute black in check only mode with diff. - black --check --diff selenium/ test/ conftest.py -l 120 - flake8 selenium/ test/ --min-python-version=3.9 - docformatter --check -r selenium/ + black --check --diff selenium/ test/ conftest.py + autoflake --check-diff selenium/ test/ conftest.py + flake8 selenium/ test/ conftest.py + docformatter --check --diff selenium/ test/ conftest.py [testenv:linting] ; A consolidated linting based recipe, responsible for executing linting tools across the code base. -; This encompasses isort for imports, black for general formatting and flake8. -; IMPORTANT: black & isort rewrite files, flake8 merely alerts to the failure. +; This encompasses: +; - isort for imports +; - black and flake8 for general formatting +; - autoflake for unused imports and variables +; - docformatter for docstrings +; IMPORTANT: +; - isort, black, autoflake, docformatter: will rewrite files +; - flake8: only alerts to the failures skip_install = true deps = - isort==5.13.2 - black==24.1.1 - flake8==6.1.0 - flake8-typing-imports==1.14.0 + isort==6.0.1 + black==25.1.0 + autoflake==2.3.1 + flake8==7.1.2 + flake8-pyproject==1.2.3 + flake8-typing-imports==1.16.0 docformatter==1.7.5 commands = isort selenium/ test/ conftest.py - black selenium/ test/ conftest.py -l 120 - flake8 selenium/ test/ --min-python-version=3.9 - docformatter --in-place -r selenium/ - -[flake8] -exclude = .tox,selenium/webdriver/common/devtools,docs/source/conf.py,*venv -# Disable this once black is applied throughout & line length is better handled. -extend-ignore = E501, E203 -# This does nothing for now as E501 is ignored. -max-line-length = 120 + black selenium/ test/ conftest.py + autoflake selenium/ test/ conftest.py + flake8 selenium/ test/ conftest.py + docformatter selenium/ test/ conftest.py