本文整理匯總了Python中_pytest.python.Function方法的典型用法代碼示例。如果您正苦於以下問題:Python python.Function方法的具體用法?Python python.Function怎麽用?Python python.Function使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類_pytest.python
的用法示例。
在下文中一共展示了python.Function方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: fillfixtures
# 需要導入模塊: from _pytest import python [as 別名]
# 或者: from _pytest.python import Function [as 別名]
def fillfixtures(function: "Function") -> None:
""" fill missing funcargs for a test function. """
warnings.warn(FILLFUNCARGS, stacklevel=2)
try:
request = function._request
except AttributeError:
# XXX this special code path is only expected to execute
# with the oejskit plugin. It uses classes with funcargs
# and we thus have to work a bit to allow this.
fm = function.session._fixturemanager
assert function.parent is not None
fi = fm.getfixtureinfo(function.parent, function.obj, None)
function._fixtureinfo = fi
request = function._request = FixtureRequest(function)
request._fillfixtures()
# prune out funcargs for jstests
newfuncargs = {}
for name in fi.argnames:
newfuncargs[name] = function.funcargs[name]
function.funcargs = newfuncargs
else:
request._fillfixtures()
示例2: _gen_items
# 需要導入模塊: from _pytest import python [as 別名]
# 或者: from _pytest.python import Function [as 別名]
def _gen_items(self, endpoint: Endpoint) -> Generator[Function, None, None]:
"""Generate all items for the given endpoint.
Could produce more than one test item if
parametrization is applied via ``pytest.mark.parametrize`` or ``pytest_generate_tests``.
This implementation is based on the original one in pytest, but with slight adjustments
to produce tests out of hypothesis ones.
"""
name = self._get_test_name(endpoint)
funcobj = self._make_test(endpoint)
cls = self._get_class_parent()
definition = create(FunctionDefinition, name=self.name, parent=self.parent, callobj=funcobj)
fixturemanager = self.session._fixturemanager
fixtureinfo = fixturemanager.getfixtureinfo(definition, funcobj, cls)
metafunc = self._parametrize(cls, definition, fixtureinfo)
if not metafunc._calls:
yield create(SchemathesisFunction, name=name, parent=self.parent, callobj=funcobj, fixtureinfo=fixtureinfo)
else:
fixtures.add_funcarg_pseudo_fixture_def(self.parent, metafunc, fixturemanager)
fixtureinfo.prune_dependency_tree()
for callspec in metafunc._calls:
subname = "{}[{}]".format(name, callspec.id)
yield create(
SchemathesisFunction,
name=subname,
parent=self.parent,
callspec=callspec,
callobj=funcobj,
fixtureinfo=fixtureinfo,
keywords={callspec.id: True},
originalname=name,
)
示例3: collect
# 需要導入模塊: from _pytest import python [as 別名]
# 或者: from _pytest.python import Function [as 別名]
def collect(self) -> List[Function]: # type: ignore
"""Generate different test items for all endpoints available in the given schema."""
try:
return [
item for endpoint in self.schemathesis_case.get_all_endpoints() for item in self._gen_items(endpoint)
]
except Exception:
pytest.fail("Error during collection")
示例4: is_potential_nosetest
# 需要導入模塊: from _pytest import python [as 別名]
# 或者: from _pytest.python import Function [as 別名]
def is_potential_nosetest(item):
# extra check needed since we do not do nose style setup/teardown
# on direct unittest style classes
return isinstance(item, python.Function) and not isinstance(
item, unittest.TestCaseFunction
)
示例5: pytest_pyfunc_call
# 需要導入模塊: from _pytest import python [as 別名]
# 或者: from _pytest.python import Function [as 別名]
def pytest_pyfunc_call(pyfuncitem: "Function") -> Optional[object]:
""" call underlying test function.
Stops at first non-None result, see :ref:`firstresult` """
示例6: is_potential_nosetest
# 需要導入模塊: from _pytest import python [as 別名]
# 或者: from _pytest.python import Function [as 別名]
def is_potential_nosetest(item: Item) -> bool:
# extra check needed since we do not do nose style setup/teardown
# on direct unittest style classes
return isinstance(item, python.Function) and not isinstance(
item, unittest.TestCaseFunction
)
示例7: _add_item_hier_parts_other
# 需要導入模塊: from _pytest import python [as 別名]
# 或者: from _pytest.python import Function [as 別名]
def _add_item_hier_parts_other(item_parts, item, item_type, hier_flag,
report_parts, rp_name=""):
"""
Add item to hierarchy of parents.
:param item_parts: Parent_items
:param item: pytest.Item
:param item_type: (SUITE, STORY, TEST, SCENARIO, STEP, BEFORE_CLASS,
BEFORE_GROUPS, BEFORE_METHOD, BEFORE_SUITE, BEFORE_TEST, AFTER_CLASS,
AFTER_GROUPS, AFTER_METHOD, AFTER_SUITE, AFTER_TEST)
:param hier_flag: bool state
:param report_parts: list of parent reports
:param rp_name: report name
:return: str rp_name
"""
for part in item_parts:
if type(part) is item_type:
if item_type is Module:
module_path = str(
item.fspath.new(dirname=rp_name,
basename=part.fspath.basename,
drive=""))
rp_name = module_path if rp_name else module_path[1:]
elif item_type in (Class, Function, UnitTestCase,
TestCaseFunction):
rp_name += ("::" if rp_name else "") + part.name
if hier_flag:
part._rp_name = rp_name
rp_name = ""
report_parts.append(part)
return rp_name
示例8: _get_item_description
# 需要導入模塊: from _pytest import python [as 別名]
# 或者: from _pytest.python import Function [as 別名]
def _get_item_description(test_item):
"""
Get description of item.
:param test_item: pytest.Item
:return string description
"""
if isinstance(test_item, (Class, Function, Module, Item)):
doc = test_item.obj.__doc__
if doc is not None:
return trim_docstring(doc)
if isinstance(test_item, DoctestItem):
return test_item.reportinfo()[2]
示例9: _add_xfail_markers
# 需要導入模塊: from _pytest import python [as 別名]
# 或者: from _pytest.python import Function [as 別名]
def _add_xfail_markers(item: Function) -> None:
"""
Mute flaky Integration Tests with custom pytest marker.
Rationale for doing this is mentioned at DCOS-45308.
"""
xfailflake_markers = [
marker for marker in item.iter_markers() if marker.name == 'xfailflake'
]
for xfailflake_marker in xfailflake_markers:
assert 'reason' in xfailflake_marker.kwargs
assert 'jira' in xfailflake_marker.kwargs
assert xfailflake_marker.kwargs['jira'].startswith('DCOS')
# Show the JIRA in the printed reason.
xfailflake_marker.kwargs['reason'] = '{jira} - {reason}'.format(
jira=xfailflake_marker.kwargs['jira'],
reason=xfailflake_marker.kwargs['reason'],
)
date_text = xfailflake_marker.kwargs['since']
try:
datetime.datetime.strptime(date_text, '%Y-%m-%d')
except ValueError:
message = (
'Incorrect date format for "since", should be YYYY-MM-DD'
)
raise ValueError(message)
# The marker is not "strict" unless that is explicitly stated.
# That means that by default, no error is raised if the test passes or
# fails.
strict = xfailflake_marker.kwargs.get('strict', False)
xfailflake_marker.kwargs['strict'] = strict
xfail_marker = pytest.mark.xfail(
*xfailflake_marker.args,
**xfailflake_marker.kwargs,
)
item.add_marker(xfail_marker)