相关疑难解决方法(0)

py.test如何以及在哪里找到固定装置

py.test在哪里以​​及如何寻找灯具?我在同一文件夹中的2个文件中有相同的代码.当我删除conftest.py时,找不到运行test_conf.py的cmdopt(也在同一个文件夹中.为什么没有搜索到sonoftest.py?

# content of test_sample.py
def test_answer(cmdopt):
    if cmdopt == "type1":
        print ("first")
    elif cmdopt == "type2":
        print ("second")
    assert 0 # to see what was printed
Run Code Online (Sandbox Code Playgroud)

conftest.py的内容

import pytest

def pytest_addoption(parser):
    parser.addoption("--cmdopt", action="store", default="type1",
        help="my option: type1 or type2")

@pytest.fixture
def cmdopt(request):
    return request.config.getoption("--cmdopt")
Run Code Online (Sandbox Code Playgroud)

sonoftest.py的内容

import pytest

def pytest_addoption(parser):
    parser.addoption("--cmdopt", action="store", default="type1",
        help="my option: type1 or type2")

@pytest.fixture
def cmdopt(request):
    return request.config.getoption("--cmdopt")
Run Code Online (Sandbox Code Playgroud)

文档说

http://pytest.org/latest/fixture.html#fixture-function

  1. pytest因test_前缀而找到test_ehlo.测试函数需要一个名为smtp的函数参数.通过查找名为smtp的夹具标记函数来发现匹配夹具功能.
  2. 调用smtp()来创建实例.
  3. 调用test_ehlo()并在测试函数的最后一行失败.

python fixtures pytest

33
推荐指数
3
解决办法
2万
查看次数

标签 统计

fixtures ×1

pytest ×1

python ×1