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.set_power_mode() 35 device.set_screen_timeout() 36 device.unlock() 37 device.go_home() 38 time.sleep(1) 39 if device.get_focus_window() == 'SystemDialog1': 40 device.click(360, 715) 41 42 yield 43 44 # logging.info('后置操作') 45 device.go_home() 46 logging.info('clear recent task') 47 device.clear_recent_task() 48 device.clean_app_data(request.param) 49 # device.stop_and_collect_hilog() 50