Skip to content

Commit

Permalink
Update deprecated functions and handle internal deprecations (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeyondEvil authored and davehunt committed Aug 23, 2018
1 parent 4085f32 commit 25376a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
28 changes: 24 additions & 4 deletions pytest_selenium/pytest_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from datetime import datetime
import os
import io
import logging

import pytest
from requests.structures import CaseInsensitiveDict
Expand All @@ -17,6 +18,9 @@

from . import drivers

LOGGER = logging.getLogger(__name__)


SUPPORTED_DRIVERS = CaseInsensitiveDict({
'BrowserStack': webdriver.Remote,
'CrossBrowserTesting': webdriver.Remote,
Expand Down Expand Up @@ -93,13 +97,29 @@ def capabilities(request, driver_class, chrome_options, firefox_options,
if all([key, options]):
capabilities[key] = _merge(
capabilities.get(key, {}), options.get(key, {}))
capabilities_marker = request.node.get_marker('capabilities')
if capabilities_marker is not None:
# add capabilities from the marker
capabilities.update(capabilities_marker.kwargs)
capabilities.update(get_capabilities_from_markers(request.node))
return capabilities


def get_capabilities_from_markers(node):
# get_marker is deprecated since pytest 3.6
# https://docs.pytest.org/en/latest/mark.html#marker-revamp-and-iteration
try:
capabilities = dict()
for level, mark in node.iter_markers_with_node('capabilities'):
LOGGER.debug('{0} marker <{1.name}> '
'contained kwargs <{1.kwargs}>'.
format(level.__class__.__name__, mark))
capabilities.update(mark.kwargs)
LOGGER.info('Capabilities from markers: {}'.format(capabilities))
return capabilities
except AttributeError:
# backwards-compat
# can be removed when minimum req pytest is 3.6
capabilities = node.get_marker('capabilities')
return capabilities.kwargs if capabilities else {}


@pytest.fixture
def driver_args():
"""Return arguments to pass to the driver service"""
Expand Down
8 changes: 8 additions & 0 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def webtext(base_url, selenium):
return selenium.find_element_by_tag_name('h1').text
""")

testdir.makefile('.cfg', setup="""
[tool:pytest]
filterwarnings =
error::DeprecationWarning
ignore:--firefox-\w+ has been deprecated:DeprecationWarning
ignore:MarkInfo:DeprecationWarning:pytest_selenium.drivers.firefox:88
""")

def runpytestqa(*args, **kwargs):
return testdir.runpytest(httpserver_base_url, '--driver', 'Firefox',
*args, **kwargs)
Expand Down

0 comments on commit 25376a9

Please sign in to comment.