Skip to content

Commit

Permalink
Rework getting browser name from args
Browse files Browse the repository at this point in the history
  • Loading branch information
NikAzanov committed May 30, 2024
1 parent 9696444 commit 7e16540
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ We follow [Semantic Versions](https://semver.org/).
# Version 2.0.0

- Use updated `qaseio` sdk (^4.0.0)
- Rework getting browser name (see `README.md`)
- Drop `Python 3.10` support
- Drop `pytest-variables` support (now use pytest options to provide browser name)
- Add `ruff` and `cspell` linters
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@ def test_demo():
"""Check qaseio plugin works as expected."""
```

Since this package is mostly used for selenium tests, you need to provide a
value for `--webdriver` flag. If you set `--webdriver=remote` and want to specify
name of remote browser (not just Remote), use `--remote-browser`
flag. This will be used in test run name and in attachments path.
Since this package is mostly used for selenium tests, it expects to get browser
name to use in Qase.io test run name and in attachments path. By default you can
provide it using `--webdriver` flag. But you can also override
`pytest_qase_browser_name` hook to implement some custom logic.
Here's default implementation of hook:

```python
@pytest.hookimpl(trylast=True)
def pytest_qase_browser_name(config: pytest.Config) -> str:
"""Try to get browser name from `webdriver` pytest option."""
return config.getoption("--webdriver")

```

To enable plugin use flag `--qase-enabled`.

Expand Down
5 changes: 5 additions & 0 deletions pytest_qaseio/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ def pytest_qase_file_storages() -> dict[str, storage.FileStorage]: # type: igno
}
"""


@pytest.hookspec(firstresult=True)
def pytest_qase_browser_name(config: pytest.Config) -> str: # type: ignore
"""Return name of browser to use in test run name and attachments path."""
13 changes: 9 additions & 4 deletions pytest_qaseio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def pytest_qase_file_storages() -> dict[str, storage.FileStorage]:
}


@pytest.hookimpl(trylast=True)
def pytest_qase_browser_name(config: pytest.Config) -> str:
"""Try to get browser name from `webdriver` pytest option."""
return config.getoption("--webdriver")


@pytest.hookimpl(trylast=True)
def pytest_configure(config: pytest.Config) -> None:
"""Configure pytest-qaseio plugin.
Expand All @@ -79,13 +85,12 @@ def pytest_configure(config: pytest.Config) -> None:
qase_enabled = config.getoption("--qase-enabled")
if not qase_enabled:
return
browser: str = config.getoption("--webdriver")
if browser == "remote":
browser = config.getoption("--remote-browser", default="chrome")

browser_name: str = config.hook.pytest_qase_browser_name()

config.pluginmanager.register(
plugin=QasePlugin(
browser=browser,
browser=browser_name,
file_storage=_get_file_storage(config),
),
name="qase_plugin",
Expand Down

0 comments on commit 7e16540

Please sign in to comment.