From 577e69940547c7669ff76c4372dd5142913748dd Mon Sep 17 00:00:00 2001 From: Serhy Date: Fri, 29 Nov 2019 13:48:07 +0200 Subject: [PATCH] Upgrade to pytest 5.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- test/appium/requirements.txt | 11 ++++---- test/appium/support/api/network_api.py | 3 +- test/appium/tests/__init__.py | 2 +- .../atomic/account_management/test_profile.py | 8 +++--- .../tests/atomic/chats/test_one_to_one.py | 1 - test/appium/tests/atomic/test_upgrade.py | 4 +-- test/appium/tests/base_test_case.py | 28 +++++++++---------- test/appium/tests/conftest.py | 9 +++--- test/appium/tests/test_chatbot.py | 11 ++++---- test/appium/views/base_view.py | 2 +- 10 files changed, 40 insertions(+), 39 deletions(-) diff --git a/test/appium/requirements.txt b/test/appium/requirements.txt index e03be20cad..d99d261d34 100644 --- a/test/appium/requirements.txt +++ b/test/appium/requirements.txt @@ -2,8 +2,7 @@ aiohttp==2.2.3 allpairspy==2.3.0 apipkg==1.4 Appium-Python-Client==0.26 -async-timeout==1.2.1 -asyncio==3.4.3 +async-timeout==3.0.1 certifi==2017.7.27.1 chardet==3.0.4 cycler==0.10.0 @@ -30,9 +29,9 @@ pycryptodome==3.6.1 pyethash==0.1.27 pyparsing==2.2.0 pysha3==1.0.2 -pytest==4.0.2 -pytest-forked==0.2 -pytest-xdist==1.22.2 +pytest==5.3.1 +pytest-forked==1.1.3 +pytest-xdist==1.30.0 python-dateutil==2.7.3 pytz==2018.4 PyYAML==4.2b4 @@ -46,6 +45,6 @@ six==1.10.0 toolz==0.9.0 urllib3==1.24.2 yarl==0.12.0 -zbarlight==1.2 +zbarlight==2.3 docker influxdb diff --git a/test/appium/support/api/network_api.py b/test/appium/support/api/network_api.py index aac8419ff1..6e61aa9db1 100644 --- a/test/appium/support/api/network_api.py +++ b/test/appium/support/api/network_api.py @@ -6,12 +6,13 @@ import requests import time from json import JSONDecodeError from decimal import Decimal +import tests class NetworkApi(object): def __init__(self): - self.network_url = 'http://api-%s.etherscan.io/api?' % pytest.config.getoption('network') + self.network_url = 'http://api-%s.etherscan.io/api?' % tests.pytest_config_global['network'] self.faucet_url = 'https://faucet-ropsten.status.im/donate' self.faucet_backup_url = 'https://faucet.ropsten.be/donate' self.headers = { diff --git a/test/appium/tests/__init__.py b/test/appium/tests/__init__.py index 0f1979ad77..f8a3ea415c 100644 --- a/test/appium/tests/__init__.py +++ b/test/appium/tests/__init__.py @@ -23,7 +23,7 @@ def get_current_time(): def debug(text: str): logging.debug(text) - +pytest_config_global = dict() test_suite_data = TestSuiteData() appium_container = AppiumContainer() diff --git a/test/appium/tests/atomic/account_management/test_profile.py b/test/appium/tests/atomic/account_management/test_profile.py index 2b8ea8b781..01282d5c21 100644 --- a/test/appium/tests/atomic/account_management/test_profile.py +++ b/test/appium/tests/atomic/account_management/test_profile.py @@ -1,4 +1,3 @@ -import pytest import re from tests import marks, bootnode_address, mailserver_address, camera_access_error_text, \ @@ -7,6 +6,7 @@ from tests import marks, bootnode_address, mailserver_address, camera_access_err from tests.base_test_case import SingleDeviceTestCase, MultipleDeviceTestCase from tests.users import transaction_senders, basic_user, ens_user from views.sign_in_view import SignInView +from tests import pytest_config_global @marks.all @@ -372,7 +372,7 @@ class TestProfileSingleDevice(SingleDeviceTestCase): sign_in_view.create_user() profile_view = sign_in_view.profile_button.click() profile_view.advanced_button.click() - if 'release' in str(pytest.config.getoption('apk')): + if 'release' in str(pytest_config_global['apk']): # TODO: should be edited after showing some text in setting when log in disabled if profile_view.log_level_setting.is_element_displayed(): self.errors.append('Log is not disabled') @@ -495,9 +495,9 @@ class TestProfileSingleDevice(SingleDeviceTestCase): profile_view.about_button.click() app_version = profile_view.app_version_text.text node_version = profile_view.node_version_text.text - if not re.search("\d{1}[.]\d{1,2}[.]\d{1,2}\s[(]\d*[)]", app_version): + if not re.search(r'\d{1}[.]\d{1,2}[.]\d{1,2}\s[(]\d*[)]', app_version): self.errors.append("App version %s didn't match expected format" % app_version) - if not re.search("StatusIM\/v.*\/android-\d{3}\/go\d{1}[.]\d{1,2}[.]\d{1,2}", node_version): + if not re.search(r'StatusIM\/v.*\/android-\d{3}\/go\d{1}[.]\d{1,2}[.]\d{1,2}', node_version): self.errors.append("Node version %s didn't match expected format" % node_version) profile_view.app_version_text.click() profile_view.back_button.click() diff --git a/test/appium/tests/atomic/chats/test_one_to_one.py b/test/appium/tests/atomic/chats/test_one_to_one.py index af5a7994dc..ef0989a9e8 100644 --- a/test/appium/tests/atomic/chats/test_one_to_one.py +++ b/test/appium/tests/atomic/chats/test_one_to_one.py @@ -1,7 +1,6 @@ import time import emoji -import pytest import random import string from datetime import datetime diff --git a/test/appium/tests/atomic/test_upgrade.py b/test/appium/tests/atomic/test_upgrade.py index e028621a61..475ab6042f 100644 --- a/test/appium/tests/atomic/test_upgrade.py +++ b/test/appium/tests/atomic/test_upgrade.py @@ -1,5 +1,5 @@ import pytest -from tests import marks +from tests import marks, pytest_config_global from tests.base_test_case import SingleDeviceTestCase from views.sign_in_view import SignInView @@ -8,7 +8,7 @@ class TestUpgradeApplication(SingleDeviceTestCase): def setup_method(self, method, **kwargs): super(TestUpgradeApplication, self).setup_method(method, app='sauce-storage:app-release.apk') - self.apk_name = ([i for i in [i for i in pytest.config.getoption('apk').split('/') if '.apk' in i]])[0] + self.apk_name = ([i for i in [i for i in pytest_config_global['apk'].split('/') if '.apk' in i]])[0] @marks.testrail_id(5713) @marks.upgrade diff --git a/test/appium/tests/base_test_case.py b/test/appium/tests/base_test_case.py index 8a74f934c6..22a2c8ccd8 100644 --- a/test/appium/tests/base_test_case.py +++ b/test/appium/tests/base_test_case.py @@ -15,7 +15,7 @@ from selenium.common.exceptions import WebDriverException from support.api.network_api import NetworkApi from support.github_report import GithubHtmlReport from support.message_reliability_report import create_one_to_one_chat_report, create_public_chat_report -from tests import test_suite_data, start_threads, appium_container +from tests import test_suite_data, start_threads, appium_container, pytest_config_global class AbstractTestCase: __metaclass__ = ABCMeta @@ -39,7 +39,7 @@ class AbstractTestCase: def print_sauce_lab_info(self, driver): sys.stdout = sys.stderr print("SauceOnDemandSessionID=%s job-name=%s" % (driver.session_id, - pytest.config.getoption('build'))) + pytest_config_global['build'])) def add_local_devices_to_capabilities(self): updated_capabilities = list() @@ -57,7 +57,7 @@ class AbstractTestCase: desired_caps = dict() desired_caps['app'] = 'sauce-storage:' + test_suite_data.apk_name - desired_caps['build'] = pytest.config.getoption('build') + desired_caps['build'] = pytest_config_global['build'] desired_caps['name'] = test_suite_data.current_test.name desired_caps['platformName'] = 'Android' desired_caps['appiumVersion'] = '1.9.1' @@ -82,16 +82,16 @@ class AbstractTestCase: @property def capabilities_local(self): desired_caps = dict() - if pytest.config.getoption('docker'): + if pytest_config_global['docker']: # apk is in shared volume directory - apk = '/root/shared_volume/%s' % pytest.config.getoption('apk') + apk = '/root/shared_volume/%s' % pytest_config_global['apk'] else: - apk = pytest.config.getoption('apk') + apk = pytest_config_global['apk'] desired_caps['app'] = apk desired_caps['deviceName'] = 'nexus_5' desired_caps['platformName'] = 'Android' desired_caps['appiumVersion'] = '1.9.1' - desired_caps['platformVersion'] = pytest.config.getoption('platform_version') + desired_caps['platformVersion'] = pytest_config_global['platform_version'] desired_caps['newCommandTimeout'] = 600 desired_caps['fullReset'] = False desired_caps['unicodeKeyboard'] = True @@ -109,7 +109,7 @@ class AbstractTestCase: @property def environment(self): - return pytest.config.getoption('env') + return pytest_config_global['env'] @property def implicitly_wait(self): @@ -164,9 +164,9 @@ class Errors(object): class SingleDeviceTestCase(AbstractTestCase): def setup_method(self, method, **kwargs): - if pytest.config.getoption('docker'): - appium_container.start_appium_container(pytest.config.getoption('docker_shared_volume')) - appium_container.connect_device(pytest.config.getoption('device_ip')) + if pytest_config_global['docker']: + appium_container.start_appium_container(pytest_config_global['docker_shared_volume']) + appium_container.connect_device(pytest_config_global['device_ip']) (executor, capabilities) = (self.executor_sauce_lab, self.capabilities_sauce_lab) if \ self.environment == 'sauce' else (self.executor_local, self.capabilities_local) @@ -177,7 +177,7 @@ class SingleDeviceTestCase(AbstractTestCase): self.driver.implicitly_wait(self.implicitly_wait) self.errors = Errors() - if pytest.config.getoption('docker'): + if pytest_config_global['docker']: appium_container.reset_battery_stats() def teardown_method(self, method): @@ -186,7 +186,7 @@ class SingleDeviceTestCase(AbstractTestCase): try: self.add_alert_text_to_report(self.driver) self.driver.quit() - if pytest.config.getoption('docker'): + if pytest_config_global['docker']: appium_container.stop_container() except (WebDriverException, AttributeError): pass @@ -255,7 +255,7 @@ class SauceMultipleDeviceTestCase(AbstractTestCase): cls.loop.close() -if pytest.config.getoption('env') == 'local': +if pytest_config_global['env'] == 'local': MultipleDeviceTestCase = LocalMultipleDeviceTestCase else: MultipleDeviceTestCase = SauceMultipleDeviceTestCase diff --git a/test/appium/tests/conftest.py b/test/appium/tests/conftest.py index 93045e5228..f30c566bc2 100644 --- a/test/appium/tests/conftest.py +++ b/test/appium/tests/conftest.py @@ -14,6 +14,7 @@ from support.api.network_api import NetworkApi from support.github_report import GithubHtmlReport from support.testrail_report import TestrailReport from tests.users import transaction_senders +import tests sauce_username = environ.get('SAUCE_USERNAME') sauce_access_key = environ.get('SAUCE_ACCESS_KEY') @@ -142,8 +143,8 @@ def is_uploaded(): def pytest_configure(config): + tests.pytest_config_global = vars(config.option) config.addinivalue_line("markers", "testrail_id(name): empty") - if config.getoption('log_steps'): import logging logging.basicConfig(level=logging.INFO) @@ -221,12 +222,12 @@ def pytest_runtest_makereport(item, call): current_test.testruns[-1].error = error if is_sauce_env: update_sauce_jobs(current_test.name, current_test.testruns[-1].jobs, report.passed) - if pytest.config.getoption('docker'): + if item.config.getoption('docker'): device_stats = appium_container.get_device_stats() - if pytest.config.getoption('bugreport'): + if item.config.getoption('bugreport'): appium_container.generate_bugreport(item.name) - build_name = pytest.config.getoption('apk') + build_name = item.config.getoption('apk') # Find type of tests that are run on the device if 'battery_consumption' in item.keywords._markers: test_group = 'battery_consumption' diff --git a/test/appium/tests/test_chatbot.py b/test/appium/tests/test_chatbot.py index 998dc0e40f..99ffccaad7 100644 --- a/test/appium/tests/test_chatbot.py +++ b/test/appium/tests/test_chatbot.py @@ -1,14 +1,15 @@ import time import pytest import numpy +from tests import pytest_config_global from tests.base_test_case import SingleDeviceTestCase from random import randint from views.sign_in_view import SignInView -running_time = int(pytest.config.getoption('running_time')) -messages_number = int(pytest.config.getoption('messages_number')) +running_time = int(pytest_config_global['running_time']) +messages_number = int(pytest_config_global['messages_number']) stop = int(time.time()) + running_time -public_keys = pytest.config.getoption('public_keys').split() +public_keys = pytest_config_global['public_keys'].split() repeats = 24 / len(public_keys) if public_keys else 0 @@ -36,11 +37,11 @@ class TestChatBot(SingleDeviceTestCase): chat.chat_message_input.send_keys(message % (counter, key)) chat.send_message_button.click() - @pytest.mark.parametrize('number', list(range(int(pytest.config.getoption('device_number'))))) + @pytest.mark.parametrize('number', list(range(int(pytest_config_global['device_number'])))) def test_chatbot_public_chat(self, number): sign_in = SignInView(self.driver) home = sign_in.create_user() - chat_name = pytest.config.getoption('chat_name') + chat_name = pytest_config_global['chat_name'] chat = home.join_public_chat(chat_name) counter = 0 while counter <= messages_number / 24: diff --git a/test/appium/views/base_view.py b/test/appium/views/base_view.py index c1d2d0b06f..3be9933ce3 100644 --- a/test/appium/views/base_view.py +++ b/test/appium/views/base_view.py @@ -610,7 +610,7 @@ class BaseView(object): logcat = self.logcat items_in_logcat = list() for key, value in kwargs.items(): - if re.findall('\W%s$|\W%s\W' % (value, value), logcat): + if re.findall(r'\W%s$|\W%s\W' % (value, value), logcat): items_in_logcat.append('%s in logcat!!!' % key.capitalize()) return items_in_logcat