From 047a9cc722579fc5302d1232dc47154005e034b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Br=C3=A4nnlund?= Date: Mon, 7 Jan 2019 14:12:44 +0100 Subject: [PATCH] Handle removal of MarkInfo in pytest 4.1.0 (#207) Fixes #206 --- pytest_selenium/drivers/cloud.py | 15 +++++++++++++++ pytest_selenium/drivers/saucelabs.py | 7 ++----- pytest_selenium/drivers/testingbot.py | 9 ++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/pytest_selenium/drivers/cloud.py b/pytest_selenium/drivers/cloud.py index aca7fc6c..e23bc5d9 100644 --- a/pytest_selenium/drivers/cloud.py +++ b/pytest_selenium/drivers/cloud.py @@ -38,3 +38,18 @@ def get_credential(self, key, envs): def uses_driver(self, driver): return driver.lower() == self.name.lower() + + +def get_markers(node): + # `MarkInfo` is removed in pytest 4.1.0 + # see https://github.com/pytest-dev/pytest/pull/4564 + try: + from _pytest.mark import MarkInfo + + keywords = node.keywords + markers = [m for m in keywords.keys() if isinstance(keywords[m], MarkInfo)] + except ImportError: + # `iter_markers` was introduced in pytest 3.6 + markers = [m.name for m in node.iter_markers()] + + return markers diff --git a/pytest_selenium/drivers/saucelabs.py b/pytest_selenium/drivers/saucelabs.py index 90d31ea2..578e7aef 100644 --- a/pytest_selenium/drivers/saucelabs.py +++ b/pytest_selenium/drivers/saucelabs.py @@ -5,12 +5,11 @@ import os import json -from _pytest.mark import MarkInfo from py.xml import html import pytest import requests -from pytest_selenium.drivers.cloud import Provider +from pytest_selenium.drivers.cloud import Provider, get_markers class SauceLabs(Provider): @@ -85,8 +84,6 @@ def pytest_selenium_runtest_makereport(item, report, summary, extra): def driver_kwargs(request, test, capabilities, **kwargs): provider = SauceLabs() - keywords = request.node.keywords - markers = [m for m in keywords.keys() if isinstance(keywords[m], MarkInfo)] _capabilities = capabilities if os.getenv("SAUCELABS_W3C") == "true": @@ -95,7 +92,7 @@ def driver_kwargs(request, test, capabilities, **kwargs): _capabilities.setdefault("username", provider.username) _capabilities.setdefault("accessKey", provider.key) _capabilities.setdefault("name", test) - tags = _capabilities.get("tags", []) + markers + tags = _capabilities.get("tags", []) + get_markers(request.node) if tags: _capabilities["tags"] = tags diff --git a/pytest_selenium/drivers/testingbot.py b/pytest_selenium/drivers/testingbot.py index 6d84e29f..dd9c9f84 100644 --- a/pytest_selenium/drivers/testingbot.py +++ b/pytest_selenium/drivers/testingbot.py @@ -3,11 +3,11 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import pytest -from _pytest.mark import MarkInfo + from py.xml import html import requests -from pytest_selenium.drivers.cloud import Provider +from pytest_selenium.drivers.cloud import Provider, get_markers HOST = "hub.testingbot.com" PORT = 443 @@ -86,12 +86,11 @@ def pytest_selenium_runtest_makereport(item, report, summary, extra): def driver_kwargs(request, test, capabilities, host, port, **kwargs): provider = TestingBot(host, port) - keywords = request.node.keywords + capabilities.setdefault("name", test) capabilities.setdefault("client_key", provider.key) capabilities.setdefault("client_secret", provider.secret) - markers = [m for m in keywords.keys() if isinstance(keywords[m], MarkInfo)] - groups = capabilities.get("groups", []) + markers + groups = capabilities.get("groups", []) + get_markers(request.node) if groups: capabilities["groups"] = groups kwargs = {