Skip to content

Commit bca930d

Browse files
authored
Require pytest 3.6 and cleanup of get_markers code (#211)
Fix #210
1 parent 2cda6e4 commit bca930d

File tree

7 files changed

+29
-60
lines changed

7 files changed

+29
-60
lines changed

docs/news.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Release Notes
22
=============
33

4+
1.16.0 (unreleased)
5+
-------------------
6+
7+
* ``pytest-selenium`` now requires pytest 3.6 or later.
8+
49
1.15.1 (2019-01-07)
510
-------------------
611

pytest_selenium/drivers/cloud.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,3 @@ def get_credential(self, key, envs):
3838

3939
def uses_driver(self, driver):
4040
return driver.lower() == self.name.lower()
41-
42-
43-
def get_markers(node):
44-
# `MarkInfo` is removed in pytest 4.1.0
45-
# see https://github.com/pytest-dev/pytest/pull/4564
46-
try:
47-
from _pytest.mark import MarkInfo
48-
49-
keywords = node.keywords
50-
markers = [m for m in keywords.keys() if isinstance(keywords[m], MarkInfo)]
51-
except ImportError:
52-
# `iter_markers` was introduced in pytest 3.6
53-
markers = [m.name for m in node.iter_markers()]
54-
55-
return markers

pytest_selenium/drivers/firefox.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,32 +98,17 @@ def firefox_options(request, firefox_path, firefox_profile):
9898

9999

100100
def get_arguments_from_markers(node):
101-
# get_marker is deprecated since pytest 3.6
102-
# https://docs.pytest.org/en/latest/mark.html#marker-revamp-and-iteration
103-
try:
104-
arguments = []
105-
[arguments.extend(m.args) for m in node.iter_markers("firefox_arguments")]
106-
return arguments
107-
except AttributeError:
108-
arguments = node.get_marker("firefox_arguments")
109-
# backwards-compat
110-
# can be removed when minimum req pytest is 3.6
111-
return arguments.args if arguments else []
101+
arguments = []
102+
for m in node.iter_markers("firefox_arguments"):
103+
arguments.extend(m.args)
104+
return arguments
112105

113106

114107
def get_preferences_from_markers(node):
115-
# get_marker is deprecated since pytest 3.6
116-
# https://docs.pytest.org/en/latest/mark.html#marker-revamp-and-iteration
117-
try:
118-
preferences = dict()
119-
for mark in node.iter_markers("firefox_preferences"):
120-
preferences.update(mark.args[0])
121-
return preferences
122-
except AttributeError:
123-
# backwards-compat
124-
# can be removed when minimum req pytest is 3.6
125-
preferences = node.get_marker("firefox_preferences")
126-
return preferences.args[0] if preferences else {}
108+
preferences = dict()
109+
for mark in node.iter_markers("firefox_preferences"):
110+
preferences.update(mark.args[0])
111+
return preferences
127112

128113

129114
@pytest.fixture(scope="session")

pytest_selenium/drivers/saucelabs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010
import requests
1111

12-
from pytest_selenium.drivers.cloud import Provider, get_markers
12+
from pytest_selenium.drivers.cloud import Provider
1313

1414

1515
class SauceLabs(Provider):
@@ -92,7 +92,8 @@ def driver_kwargs(request, test, capabilities, **kwargs):
9292
_capabilities.setdefault("username", provider.username)
9393
_capabilities.setdefault("accessKey", provider.key)
9494
_capabilities.setdefault("name", test)
95-
tags = _capabilities.get("tags", []) + get_markers(request.node)
95+
markers = [x.name for x in request.node.iter_markers()]
96+
tags = _capabilities.get("tags", []) + markers
9697
if tags:
9798
_capabilities["tags"] = tags
9899

pytest_selenium/drivers/testingbot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from py.xml import html
88
import requests
99

10-
from pytest_selenium.drivers.cloud import Provider, get_markers
10+
from pytest_selenium.drivers.cloud import Provider
1111

1212
HOST = "hub.testingbot.com"
1313
PORT = 443
@@ -90,7 +90,8 @@ def driver_kwargs(request, test, capabilities, host, port, **kwargs):
9090
capabilities.setdefault("name", test)
9191
capabilities.setdefault("client_key", provider.key)
9292
capabilities.setdefault("client_secret", provider.secret)
93-
groups = capabilities.get("groups", []) + get_markers(request.node)
93+
markers = [x.name for x in request.node.iter_markers()]
94+
groups = capabilities.get("groups", []) + markers
9495
if groups:
9596
capabilities["groups"] = groups
9697
kwargs = {

pytest_selenium/pytest_selenium.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,15 @@ def capabilities(
105105

106106

107107
def get_capabilities_from_markers(node):
108-
# get_marker is deprecated since pytest 3.6
109-
# https://docs.pytest.org/en/latest/mark.html#marker-revamp-and-iteration
110-
try:
111-
capabilities = dict()
112-
for level, mark in node.iter_markers_with_node("capabilities"):
113-
LOGGER.debug(
114-
"{0} marker <{1.name}> "
115-
"contained kwargs <{1.kwargs}>".format(level.__class__.__name__, mark)
116-
)
117-
capabilities.update(mark.kwargs)
118-
LOGGER.info("Capabilities from markers: {}".format(capabilities))
119-
return capabilities
120-
except AttributeError:
121-
# backwards-compat
122-
# can be removed when minimum req pytest is 3.6
123-
capabilities = node.get_marker("capabilities")
124-
return capabilities.kwargs if capabilities else {}
108+
capabilities = dict()
109+
for level, mark in node.iter_markers_with_node("capabilities"):
110+
LOGGER.debug(
111+
"{0} marker <{1.name}> "
112+
"contained kwargs <{1.kwargs}>".format(level.__class__.__name__, mark)
113+
)
114+
capabilities.update(mark.kwargs)
115+
LOGGER.info("Capabilities from markers: {}".format(capabilities))
116+
return capabilities
125117

126118

127119
@pytest.fixture

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
url="https://github.com/pytest-dev/pytest-selenium",
1111
packages=["pytest_selenium", "pytest_selenium.drivers"],
1212
install_requires=[
13-
"pytest>=3.0",
13+
"pytest>=3.6",
1414
"pytest-base-url",
1515
"pytest-html>=1.14.0",
1616
"pytest-variables>=1.5.0",

0 commit comments

Comments
 (0)