有没有办法从一个简单的函数中引用(并调用)一个 pytest 固定装置,它本身既不是 test_* 函数也不是固定装置?
可以使用夹具的已知示例:
1)
def test_mytest( some_cool_pytest_fixture_name, the, rest of, my, args):
blah
blah
some_cool_pytest_fixture_name(args)
blah
2)
@pytest.fixture()
def my_new_fixture( some_cool_pytest_fixture_name, the, rest of, my, args):
blah
blah
some_cool_pytest_fixture_name(args)
blah
Run Code Online (Sandbox Code Playgroud)
我希望能够做到这一点:3)
def my_simple_function( the, rest of, my, args):
blah
blah
outright.reference.this.pytest.fixture.some_cool_pytest_fixture_name(args)
blah
Run Code Online (Sandbox Code Playgroud)
笔记:
from pytest import record_xml_property as property_handler
** E ImportError: cannot import name record_xml_property**
Run Code Online (Sandbox Code Playgroud)
^^^ 这是在具有record_xml_property的系统上
我的愿望是能够做这样的事情:
try:
from pytest import record_xml_property as property_handler
except:
@pytest.fixture()
def property_handler(mykey, myval):
print('{0}={1}'.format(mykey,myval)
Run Code Online (Sandbox Code Playgroud)
^^^ 如果以上可以成功,那么我总是可以依靠property_handler …