Skip to main content

Pytest

Dogu provides pytest integration for users who use pytest.
The pytest-dogu-sdk plugin allows you to check the test results of the Dogu Routine.
Like this.

pytest-dogu-sdk

Requirements

  • Python 3.9 or higher
Python environment variable setting

If you are using MacOS, see Environment variable document.

Configuration

  • install pytest-dogu-sdk package to your project.
# using pip
pip install pytest-dogu-sdk

# using poetry
poetry add -D pytest-dogu-sdk
  • register pytest-dogu-sdk plugin to your root conftest.py file.
pytest_plugins = [
"pytest_dogu_sdk",
]
pytest plugin discovery order

The plugin discovery order can be found in this official document.

  • register your custom DoguClient to your root conftest.py file with pytest_dogu_sdk_create_client hook.

See References document for more details.

Example

The example below shows how to use selenium webdriver as a DoguClient.

from typing import Any, Dict

from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver import ChromeOptions, Remote
from pytest_dogu_sdk.dogu_config import DoguConfig
from pytest_dogu_sdk.dogu_hooks import DoguClient

# ...

def pytest_dogu_create_client() -> DoguClient:
class SeleniumDoguClient(DoguClient):
def on_setup(self, dogu_config: DoguConfig):
options = ChromeOptions()
options.set_capability(
"dogu:options",
{
"organizationId": dogu_config.organization_id,
"projectId": dogu_config.project_id,
"token": dogu_config.token,
"runsOn": dogu_config.runs_on,
"browserName": dogu_config.browser_name,
"browserVersion": dogu_config.browser_version,
},
)
return Remote(
command_executor=f"{dogu_config.api_base_url}/remote/wd/hub",
options=options,
)

@property
def dogu_results(self) -> Dict[str, Any]:
return self.cast(WebDriver).capabilities["dogu:results"]

def on_teardown(self):
if self.impl:
self.cast(WebDriver).quit()

return SeleniumDoguClient()
info

see full example for more details.