繁体   English   中英

Pytest Addoption 配置不起作用

[英]Pytest Addoption configuration not working

我已经在 Pytest 上构建了一个框架,以在 QA、UAT、生产等多种环境中测试 web 应用程序。现在每个服务器的 url 和凭据都不同。 因此,我为不同的服务器创建了不同的 conf.yml 文件,例如生产 =“conf.yml”,QA“qaconf.yml”等。现在我以下面的方式使用了 pytest_addoption,并且在命令本身中我应该提到哪个服务器,我想执行测试套件

代码

def pytest_addoption(parser):
    parser.addoption("--conffile",action="store",help="config file")

@pytest.fixture(scope="function")
def selenium_driver(request):
    config_param = {}
    config_param["conffile"] = request.config.getoption("--conffile")
    # conffile = request.config.getoption("--conffile")
    import pdb;pdb.set_trace()
    conf = TestConfig()
    test = conf.testconf['Test']['AnandRathi']
    driver = conf.WebDriver()
    driver.get(test['Url'])
    request.cls.driver = driver
    yield driver
    driver.close()

现在在运行测试套件时,我正在使用以下命令但出现错误

pytest -v -s --conffile=conf

错误

pytest: error: unrecognized arguments: --conffile=conf
  inifile: None

不知道在这种情况下我做错了什么? 任何人都可以帮忙吗? 还提供下面的 yml 文件

Browser: chrome
Test:
  AnandRathi:
    Url: https://sarathiaapka.com/
    Data:
      Username: "abcdefgh"
      Password: "*****"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM