gpt4 book ai didi

python - 直接调用 fixture "setUp"。 Fixtures 不应该被直接调用

转载 作者:行者123 更新时间:2023-12-04 14:18:25 27 4
gpt4 key购买 nike

命令行

python3 -m pytest src/spec/ --app=android

conftest.py

import pytest

def pytest_addoption(parser):
parser.addoption('--app')

@pytest.fixture(scope="session")
def app(request):
return request.config.getoption("--app")

驱动.py

import pytest

class Driver(unittest.TestCase):

def __init__(self, driver):
unittest.TestCase.__init__(self, driver)

@pytest.fixture(autouse=True)
def setUp(self, app):
self.app = app

if self.app == 'ios':
desired_caps = {}
desired_caps['platformName'] = 'ios'
desired_caps['platformVersion'] = ''
desired_caps['deviceName'] = 'PF'

elif self.app == 'android':
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = ''
desired_caps['deviceName'] = 'PF'
desired_caps['appPackage'] = 'com.wdiodemoapp'
desired_caps['appActivity'] = 'com.wdiodemoapp.MainActivity'

self.driver = webdriver.Remote("http://0.0.0.0:4723/wd/hub", desired_caps)

enter image description here

最佳答案

问题是 unittestpytest 混淆的原因。下面修复了它。

def setUp(self):
Driver.fix

if self.app == 'ios':
desired_caps = {}
desired_caps['platformName'] = 'ios'
desired_caps['platformVersion'] = ''
desired_caps['deviceName'] = 'PF'

elif self.app == 'android':
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = ''
desired_caps['deviceName'] = 'PF'
desired_caps['appPackage'] = 'com.wdiodemoapp'
desired_caps['appActivity'] = 'com.wdiodemoapp.MainActivity'

@pytest.fixture(autouse=True)
def fix(self, app):
self.app = app

关于python - 直接调用 fixture "setUp"。 Fixtures 不应该被直接调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57884245/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com