From 25376a93ba39b14f6161be987a973d426b3e109b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Br=C3=A4nnlund?= Date: Thu, 23 Aug 2018 16:32:05 +0200 Subject: [PATCH] Update deprecated functions and handle internal deprecations (#183) --- pytest_selenium/pytest_selenium.py | 28 ++++++++++++++++++++++++---- testing/conftest.py | 8 ++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pytest_selenium/pytest_selenium.py b/pytest_selenium/pytest_selenium.py index a29996f5..4074881b 100644 --- a/pytest_selenium/pytest_selenium.py +++ b/pytest_selenium/pytest_selenium.py @@ -7,6 +7,7 @@ from datetime import datetime import os import io +import logging import pytest from requests.structures import CaseInsensitiveDict @@ -17,6 +18,9 @@ from . import drivers +LOGGER = logging.getLogger(__name__) + + SUPPORTED_DRIVERS = CaseInsensitiveDict({ 'BrowserStack': webdriver.Remote, 'CrossBrowserTesting': webdriver.Remote, @@ -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""" diff --git a/testing/conftest.py b/testing/conftest.py index 59db993b..dd95ad02 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -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)