conftest.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # coding: utf-8
  2. import adbutils
  3. import pytest
  4. import uiautomator2 as u2
  5. @pytest.fixture(scope="module")
  6. def d(device):
  7. _d = device
  8. _d.settings['operation_delay'] = (0.2, 0.2)
  9. _d.settings['operation_delay_methods'] = ['click', 'swipe']
  10. return _d
  11. @pytest.fixture
  12. def package_name():
  13. return "io.appium.android.apis"
  14. @pytest.fixture(scope="function")
  15. def dev(d: u2.Device, package_name) -> u2.Device: # type: ignore
  16. d.watcher.reset()
  17. d.app_start(package_name, stop=True)
  18. yield d
  19. # run parallel
  20. # py.test --tx "3*popen" --dist=load test_device.py -q --tb=line
  21. #def read_device_list() -> list:
  22. # return [v.serial for v in adbutils.adb.device_list()]
  23. #def pytest_configure(config):
  24. # # read device list if we are on the master
  25. # if not hasattr(config, "slaveinput"):
  26. # config.devlist = read_device_list()
  27. # def pytest_configure_node(node):
  28. # # the master for each node fills slaveinput dictionary
  29. # # which pytest-xdist will transfer to the subprocess
  30. # serial = node.slaveinput["serial"] = node.config.devlist.pop()
  31. # node.config.devlist.insert(0, serial)
  32. @pytest.fixture(scope="session")
  33. def device(request):
  34. return u2.connect()
  35. # slaveinput = getattr(request.config, "slaveinput", None)
  36. # if slaveinput is None: # single-process execution
  37. # serial = read_device_list()[0]
  38. # else: # running in a subprocess here
  39. # serial = slaveinput["serial"]
  40. # print("SERIAL:", serial)
  41. # return u2.connect(serial)