Skip to content

Commit a316597

Browse files
authored
chore: Remove unittest dependency (appium#488)
* Removed unnecessary codes from calling super * Removed unittest dependency * Upgrade the dependencies to the latest * Removed unused args * Review comments
1 parent 4a833f2 commit a316597

39 files changed

+197
-419
lines changed

Pipfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ url = "https://pypi.org/simple"
44
verify_ssl = true
55

66
[dev-packages]
7-
pre-commit = "~=1.13"
7+
pre-commit = "~=1.21"
88

99
[packages]
1010
selenium = "~=3.141"
1111

12-
autopep8 = "~=1.4"
12+
autopep8 = "~=1.5"
1313

14-
pytest = "~=4.0"
15-
pytest-cov = "~=2.6"
14+
pytest = "~=5.3"
15+
pytest-cov = "~=2.8"
1616

17-
tox = "~=3.6"
18-
tox-travis = "~=0.11"
17+
tox = "~=3.14"
18+
tox-travis = "~=0.12"
1919

2020
httpretty = "~=0.9"
2121
python-dateutil = "~=2.8"

appium/webdriver/errorhandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class MobileErrorHandler(errorhandler.ErrorHandler):
2424
def check_response(self, response: Dict) -> None:
2525
try:
26-
super(MobileErrorHandler, self).check_response(response)
26+
super().check_response(response)
2727
except WebDriverException as wde:
2828
if wde.msg == 'No such context found.':
2929
raise NoSuchContextException(wde.msg, wde.screen, wde.stacktrace)

appium/webdriver/webdriver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class WebDriver(
148148
def __init__(self, command_executor: str = 'http://127.0.0.1:4444/wd/hub',
149149
desired_capabilities: Optional[Dict] = None, browser_profile: str = None, proxy: str = None, keep_alive: bool = True, direct_connection: bool = False):
150150

151-
super(WebDriver, self).__init__(
151+
super().__init__(
152152
AppiumConnection(command_executor, keep_alive=keep_alive),
153153
desired_capabilities,
154154
browser_profile,

test/functional/android/activities_tests.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import unittest
17-
1816
from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase
1917

2018

21-
class ActivitiesTests(BaseTestCase):
19+
class TestActivities(BaseTestCase):
2220
def test_current_activity(self) -> None:
2321
activity = self.driver.current_activity
24-
self.assertEqual('.ApiDemos', activity)
22+
assert '.ApiDemos' == activity
2523

2624
def test_start_activity_this_app(self) -> None:
2725
self.driver.start_activity(APIDEMO_PKG_NAME, ".ApiDemos")
@@ -39,9 +37,4 @@ def test_start_activity_other_app(self) -> None:
3937

4038
def _assert_activity_contains(self, activity: str) -> None:
4139
current = self.driver.current_activity
42-
self.assertTrue(activity in current)
43-
44-
45-
if __name__ == '__main__':
46-
suite = unittest.TestLoader().loadTestsFromTestCase(ActivitiesTests)
47-
unittest.TextTestRunner(verbosity=2).run(suite)
40+
assert activity in current

test/functional/android/applications_tests.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,70 +13,63 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import unittest
1716
from time import sleep
1817

18+
import pytest
19+
1920
from appium.webdriver.applicationstate import ApplicationState
2021

2122
from .helper.test_helper import APIDEMO_PKG_NAME, BaseTestCase
2223

2324

24-
class ApplicationsTests(BaseTestCase):
25+
class TestApplications(BaseTestCase):
2526

2627
def test_background_app(self) -> None:
2728
self.driver.background_app(1)
2829
sleep(3)
2930
self.driver.launch_app()
3031

3132
def test_is_app_installed(self) -> None:
32-
self.assertFalse(self.driver.is_app_installed('sdfsdf'))
33-
self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME))
33+
assert not self.driver.is_app_installed('sdfsdf')
34+
assert self.driver.is_app_installed(APIDEMO_PKG_NAME)
3435

36+
@pytest.mark.skip('This causes the server to crash. no idea why')
3537
def test_install_app(self) -> None:
36-
self.skipTest('This causes the server to crash. no idea why')
37-
self.assertFalse(self.driver.is_app_installed('io.selendroid.testapp'))
38+
assert not self.driver.is_app_installed('io.selendroid.testapp')
3839
self.driver.install_app('/Users/isaac/code/python-client/test/apps/selendroid-test-app.apk')
39-
self.assertTrue(self.driver.is_app_installed('io.selendroid.testapp'))
40+
assert self.driver.is_app_installed('io.selendroid.testapp')
4041

4142
def test_remove_app(self) -> None:
42-
self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME))
43+
assert self.driver.is_app_installed(APIDEMO_PKG_NAME)
4344
self.driver.remove_app(APIDEMO_PKG_NAME)
44-
self.assertFalse(self.driver.is_app_installed(APIDEMO_PKG_NAME))
45+
assert not self.driver.is_app_installed(APIDEMO_PKG_NAME)
4546

4647
def test_close_and_launch_app(self) -> None:
4748
self.driver.close_app()
4849
self.driver.launch_app()
4950
activity = self.driver.current_activity
50-
self.assertEqual('.ApiDemos', activity)
51+
assert '.ApiDemos' == activity
5152

5253
def test_app_management(self) -> None:
5354
app_id = self.driver.current_package
54-
self.assertEqual(self.driver.query_app_state(app_id),
55-
ApplicationState.RUNNING_IN_FOREGROUND)
55+
assert self.driver.query_app_state(app_id) == ApplicationState.RUNNING_IN_FOREGROUND
5656
self.driver.background_app(-1)
57-
self.assertTrue(self.driver.query_app_state(app_id) <
58-
ApplicationState.RUNNING_IN_FOREGROUND)
57+
assert self.driver.query_app_state(app_id) < ApplicationState.RUNNING_IN_FOREGROUND
5958
self.driver.activate_app(app_id)
60-
self.assertEqual(self.driver.query_app_state(app_id),
61-
ApplicationState.RUNNING_IN_FOREGROUND)
59+
assert self.driver.query_app_state(app_id) == ApplicationState.RUNNING_IN_FOREGROUND
6260

6361
def test_app_strings(self) -> None:
6462
strings = self.driver.app_strings()
65-
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
63+
assert u'You can\'t wipe my data, you are a monkey!' == strings[u'monkey_wipe_data']
6664

6765
def test_app_strings_with_language(self) -> None:
6866
strings = self.driver.app_strings('en')
69-
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
67+
assert u'You can\'t wipe my data, you are a monkey!' == strings[u'monkey_wipe_data']
7068

7169
def test_app_strings_with_language_and_file(self) -> None:
7270
strings = self.driver.app_strings('en', 'some_file')
73-
self.assertEqual(u'You can\'t wipe my data, you are a monkey!', strings[u'monkey_wipe_data'])
71+
assert u'You can\'t wipe my data, you are a monkey!' == strings[u'monkey_wipe_data']
7472

7573
def test_reset(self) -> None:
7674
self.driver.reset()
77-
self.assertTrue(self.driver.is_app_installed(APIDEMO_PKG_NAME))
78-
79-
80-
if __name__ == '__main__':
81-
suite = unittest.TestLoader().loadTestsFromTestCase(ApplicationsTests)
82-
unittest.TextTestRunner(verbosity=2).run(suite)
75+
assert self.driver.is_app_installed(APIDEMO_PKG_NAME)

test/functional/android/chrome_tests.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import unittest
16-
1715
from appium import webdriver
1816

1917
from .helper.desired_capabilities import get_desired_capabilities
2018

2119

22-
class ChromeTests(unittest.TestCase):
23-
def setUp(self) -> None:
20+
class TestChrome(object):
21+
def setup_method(self) -> None:
2422
caps = get_desired_capabilities()
2523
caps['browserName'] = 'Chrome'
2624
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', caps)
2725

28-
def tearDown(self) -> None:
26+
def teardown_method(self) -> None:
2927
self.driver.quit()
3028

3129
def test_find_single_element(self) -> None:
3230
self.driver.get('http://10.0.2.2:4723/test/guinea-pig')
3331
self.driver.find_element_by_link_text('i am a link').click()
3432

35-
self.assertTrue('I am some other page content' in self.driver.page_source)
36-
37-
38-
if __name__ == '__main__':
39-
suite = unittest.TestLoader().loadTestsFromTestCase(ChromeTests)
40-
unittest.TextTestRunner(verbosity=2).run(suite)
33+
assert 'I am some other page content' in self.driver.page_source

test/functional/android/common_tests.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import unittest
1716
from time import sleep
1817

18+
import pytest
1919
from selenium.common.exceptions import NoSuchElementException
2020

2121
from appium.webdriver.common.mobileby import MobileBy
@@ -28,28 +28,27 @@
2828
)
2929

3030

31-
class CommonTests(BaseTestCase):
31+
class TestCommon(BaseTestCase):
3232

3333
def test_current_package(self) -> None:
34-
self.assertEqual(APIDEMO_PKG_NAME, self.driver.current_package)
34+
assert APIDEMO_PKG_NAME == self.driver.current_package
3535

36+
@pytest.mark.skip('Not sure how to set this up to run')
3637
def test_end_test_coverage(self) -> None:
37-
self.skipTest('Not sure how to set this up to run')
3838
self.driver.end_test_coverage(intent='android.intent.action.MAIN', path='')
3939
sleep(5)
4040

41+
# TODO Due to unexpected dialog, "System UI isn't responding"
42+
@pytest.mark.skipif(condition=is_ci(), reason='Need to fix flaky test during running on CI.')
4143
def test_open_notifications(self) -> None:
42-
if is_ci():
43-
# TODO Due to unexpected dialog, "System UI isn't responding"
44-
self.skipTest('Need to fix flaky test during running on CI.')
4544
for word in ['App', 'Notification', 'Status Bar', ':-|']:
4645
wait_for_element(self.driver, MobileBy.ANDROID_UIAUTOMATOR,
4746
f'new UiSelector().text("{word}")').click()
4847

4948
self.driver.open_notifications()
5049
sleep(1)
51-
self.assertRaises(NoSuchElementException,
52-
self.driver.find_element_by_android_uiautomator, 'new UiSelector().text(":-|")')
50+
with pytest.raises(NoSuchElementException):
51+
self.driver.find_element_by_android_uiautomator, 'new UiSelector().text(":-|")'
5352

5453
els = self.driver.find_elements_by_class_name('android.widget.TextView')
5554
# sometimes numbers shift
@@ -61,14 +60,9 @@ def test_open_notifications(self) -> None:
6160
title = True
6261
elif text == 'I am ok':
6362
body = True
64-
self.assertTrue(title)
65-
self.assertTrue(body)
63+
assert title
64+
assert body
6665

6766
self.driver.keyevent(4)
6867
sleep(1)
6968
self.driver.find_element_by_android_uiautomator('new UiSelector().text(":-|")')
70-
71-
72-
if __name__ == '__main__':
73-
suite = unittest.TestLoader().loadTestsFromTestCase(CommonTests)
74-
unittest.TextTestRunner(verbosity=2).run(suite)

test/functional/android/context_switching_tests.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import unittest
16-
1715
import pytest
1816

1917
from appium import webdriver
@@ -23,43 +21,39 @@
2321

2422

2523
@pytest.mark.skip(reason="Need to fix broken test")
26-
class ContextSwitchingTests(unittest.TestCase):
27-
def setUp(self) -> None:
24+
class TestContextSwitching(object):
25+
def setup_method(self) -> None:
2826
desired_caps = desired_capabilities.get_desired_capabilities('selendroid-test-app.apk')
2927
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
3028

31-
def tearDown(self) -> None:
29+
def teardown_method(self) -> None:
3230
self.driver.quit()
3331

3432
def test_contexts_list(self) -> None:
3533
self._enter_webview()
3634
contexts = self.driver.contexts
37-
self.assertEqual(2, len(contexts))
35+
assert 2 == len(contexts)
3836

3937
def test_move_to_correct_context(self) -> None:
4038
self._enter_webview()
41-
self.assertEqual('WEBVIEW_io.selendroid.testapp', self.driver.current_context)
39+
assert 'WEBVIEW_io.selendroid.testapp' == self.driver.current_context
4240

4341
def test_actually_in_webview(self) -> None:
4442
self._enter_webview()
4543
self.driver.find_element_by_css_selector('input[type=submit]').click()
4644
el = self.driver.find_element_by_xpath("//h1[contains(., 'This is my way')]")
47-
self.assertIsNot(None, el)
45+
assert el is not None
4846

4947
def test_move_back_to_native_context(self) -> None:
5048
self._enter_webview()
5149
self.driver.switch_to.context(None)
52-
self.assertEqual('NATIVE_APP', self.driver.current_context)
50+
assert 'NATIVE_APP' == self.driver.current_context
5351

5452
def test_set_invalid_context(self) -> None:
55-
self.assertRaises(NoSuchContextException, self.driver.switch_to.context, 'invalid name')
53+
with pytest.raises(NoSuchContextException):
54+
self.driver.switch_to.context('invalid name')
5655

5756
def _enter_webview(self) -> None:
5857
btn = self.driver.find_element_by_name('buttonStartWebviewCD')
5958
btn.click()
6059
self.driver.switch_to.context('WEBVIEW')
61-
62-
63-
if __name__ == '__main__':
64-
suite = unittest.TestLoader().loadTestsFromTestCase(ContextSwitchingTests)
65-
unittest.TextTestRunner(verbosity=2).run(suite)

test/functional/android/device_time_tests.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,13 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import unittest
17-
1816
from dateutil.parser import parse
1917

2018
from .helper.test_helper import BaseTestCase
2119

2220

23-
class DeviceTimeTests(BaseTestCase):
21+
class TestDeviceTime(BaseTestCase):
2422
def test_device_time(self) -> None:
2523
date_time = self.driver.device_time
2624
# convert to date ought to work
2725
parse(date_time)
28-
29-
30-
if __name__ == '__main__':
31-
suite = unittest.TestLoader().loadTestsFromTestCase(DeviceTimeTests)
32-
unittest.TextTestRunner(verbosity=2).run(suite)

test/functional/android/finger_print_tests.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,10 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
import unittest
17-
1816
from .helper.test_helper import BaseTestCase
1917

2018

21-
class FingerPrintTests(BaseTestCase):
19+
class TestFingerPrint(BaseTestCase):
2220
def test_finger_print(self) -> None:
2321
result = self.driver.finger_print(1)
24-
self.assertEqual(None, result)
25-
26-
27-
if __name__ == '__main__':
28-
suite = unittest.TestLoader().loadTestsFromTestCase(FingerPrintTests)
29-
unittest.TextTestRunner(verbosity=2).run(suite)
22+
assert result is None

0 commit comments

Comments
 (0)