Skip to content

Commit

Permalink
Handle removal of MarkInfo in pytest 4.1.0 (pytest-dev#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil authored and nicoddemus committed Jan 7, 2019
1 parent 1ced400 commit 047a9cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
15 changes: 15 additions & 0 deletions pytest_selenium/drivers/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions pytest_selenium/drivers/saucelabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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":
Expand All @@ -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

Expand Down
9 changes: 4 additions & 5 deletions pytest_selenium/drivers/testingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 047a9cc

Please sign in to comment.