1import logging 2import os.path 3import time 4 5import pytest 6 7from utils.device import Device 8 9BASE_DIR = os.path.dirname(__file__) 10 11 12def pytest_addoption(parser): 13 parser.addoption('--sn', default='') 14 15 16@pytest.fixture(scope='session', autouse=True) 17def device(request): 18 sn = request.config.option.sn 19 return Device(sn) 20 21 22@pytest.fixture(scope='module') 23def setup_teardown(request, device): 24 # logging.info('setup--------') 25 current_case = os.path.basename(request.path)[:-3] 26 # 日志截图等保存路径 27 device.report_path = os.path.realpath(os.path.dirname(request.config.option.htmlpath)) 28 logging.info('set current report path as {}'.format(device.report_path)) 29 device.resource_path = os.path.join(os.path.dirname(__file__), 'resource') 30 os.makedirs(device.report_path, exist_ok=True) 31 # device.rm_faultlog() 32 # device.start_hilog() 33 device.wakeup() 34 device.unlock() 35 time.sleep(2) 36 device.set_power_mode() 37 device.set_screen_timeout() 38 device.unlock() 39 time.sleep(2) 40 device.go_home() 41 time.sleep(1) 42 if device.get_focus_window() == 'SystemDialog1': 43 device.click(360, 800) 44 time.sleep(2) 45 if device.get_focus_window() == 'SystemDialog1': 46 device.click(595, 555) 47 time.sleep(10) 48 #device.click(360, 800) 49 device.click(360, 1245) 50 time.sleep(1) 51 #device.click(360, 1245) 52 53 54 yield 55 56 # logging.info('后置操作') 57 device.go_home() 58 logging.info('clear recent task') 59 device.clear_recent_task() 60 device.clean_app_data(request.param) 61 # device.stop_and_collect_hilog() 62