本文介绍了夹具“设置"直接调用.Fixtures 不应该被直接调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

命令行

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")

driver.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)

推荐答案

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

The issue is cos of mixing up of unittest with pytest. The below fixed it.

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

这篇关于夹具“设置"直接调用.Fixtures 不应该被直接调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 18:23