Skip to content

Pytest upgrade from pytest 3 to pytest 6 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
**/.cache
**/__pycache__

**/.vscode
**/.vscode

.pytest_appium.egg-info
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably just make this *.egg-info tbh

6 changes: 4 additions & 2 deletions pytest_appium/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import urllib #.request
import time
import requests


def _decode_response(response):
Expand All @@ -12,8 +13,9 @@ def _decode_response(response):
return json.loads(data.decode(encoding))


def get_json(url):
return _decode_response(urllib.request.urlopen(url))
def get_json(url, headers: dict=None):
r = requests.get(url, headers=headers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for not also updating the post if we're swapping urlib for requests?

return r.json()


def post_json(url, data):
Expand Down
15 changes: 8 additions & 7 deletions pytest_appium/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def session_capabilities(request, variables):
return capabilities


@pytest.fixture
def driver_kwargs(request, capabilities):
""" """
# Assertions of capabilitys should go here
Expand All @@ -64,13 +63,15 @@ def driver_kwargs(request, capabilities):
return kwargs


@pytest.fixture
def driver_class(request):
"""Appium driver class"""
return webdriver.Remote

@pytest.fixture
def driver_class_fixture(request):
return driver_class(request)


@pytest.yield_fixture
def driver(request, driver_class, driver_kwargs):
"""Returns a AppiumDriver instance based on options and capabilities"""
driver = driver_class(**driver_kwargs)
Expand Down Expand Up @@ -137,7 +138,7 @@ def _appium_is_device_available(appium_wd_api_endpoint, desiredCapabilities={},
#'ios_device_available': appium_is_device_available_ios,
}

@pytest.yield_fixture(scope='session')
@pytest.fixture(scope='session')
def driver_session_(request, session_capabilities):
"""
Appium Session
Expand Down Expand Up @@ -176,7 +177,7 @@ def wait_for_appium():
raise Exception(f"""Unable to connect to Appium server {appium_url}""")


@pytest.yield_fixture
@pytest.fixture
def driver_session(request, driver_session_):
"""
Appium Session
Expand All @@ -186,7 +187,7 @@ def driver_session(request, driver_session_):
#driver_session_.reset()


@pytest.yield_fixture
@pytest.fixture
def appium(driver_session):
"""Alias for driver_session"""
yield driver_session
Expand All @@ -213,7 +214,7 @@ def test_example():
# Filter tests that are not targeted for this platform
current_platform = config._variables.get('capabilities',{}).get('platformName','').lower()
def select_test(item):
platform_marker = item.get_marker("platform")
platform_marker = item.get_closest_marker("platform")
if platform_marker and platform_marker.args and current_platform:
test_platform_specified = platform_marker.args[0].lower()
if test_platform_specified != current_platform:
Expand Down