本文整理汇总了Python中_pytest.fixtures.FixtureRequest方法的典型用法代码示例。如果您正苦于以下问题:Python fixtures.FixtureRequest方法的具体用法?Python fixtures.FixtureRequest怎么用?Python fixtures.FixtureRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_pytest.fixtures
的用法示例。
在下文中一共展示了fixtures.FixtureRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_weather_type_programmatic
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def test_weather_type_programmatic(
weather_type: str,
max_err: float,
weather_env: HolodeckEnvironment,
request: FixtureRequest,
) -> None:
"""Validate that weather type can be set programmatically by comparing
RGB sensor data with saved baseline data
Args:
weather_type: Type of weather in ["sunny", "cloudy", "rain"]
max_err: Maximum mean squared error between sensor data and baseline
weather_env: Environment fixture shared by programmatic tests
data allowed for test to pass
request: pytest fixture request information
"""
weather_env.weather.set_weather(weather_type)
weather_env.tick(5)
err = compare_rgb_sensor_data_with_baseline(
weather_env.tick()["TestCamera"],
request.fspath.dirname,
"weather_type_{}".format(weather_type),
)
assert err < max_err
示例2: weather_env
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def weather_env(request: FixtureRequest):
"""Get basic MazeWorld environment with RGBCamera sensor for use in
visual comparison tests where environments can be reused. Cached per test.
Args:
request: pytest fixture request information
"""
global cur_programmatic_weather_env
cur_programmatic_test_name = request.function.__name__
if (
cur_programmatic_test_name != last_programmatic_test_name
or cur_programmatic_weather_env is None
):
cur_programmatic_weather_env = env_with_config(weather_config)
return cur_programmatic_weather_env
示例3: test_weather_time_scenario
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def test_weather_time_scenario(
hour: float, max_err: float, request: FixtureRequest
) -> None:
"""Validate that time can be set with scenario by comparing RGB sensor
data with saved baseline data
Args:
hour: The hour in 24-hour format: [0, 23].
max_err: Maximum mean squared error between sensor
data and baseline
request: pytest fixture request information
"""
config = weather_config.copy()
config["weather"] = {"hour": hour}
with env_with_config(config) as env:
env.tick(5)
err = compare_rgb_sensor_data_with_baseline(
env.tick()["TestCamera"],
request.fspath.dirname,
"weather_time_{}".format(hour),
)
assert err < max_err
示例4: _setup_fixtures
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def _setup_fixtures(doctest_item):
"""
Used by DoctestTextfile and DoctestItem to setup fixture information.
"""
def func():
pass
doctest_item.funcargs = {}
fm = doctest_item.session._fixturemanager
doctest_item._fixtureinfo = fm.getfixtureinfo(
node=doctest_item, func=func, cls=None, funcargs=False
)
fixture_request = FixtureRequest(doctest_item)
fixture_request._fillfixtures()
return fixture_request
示例5: record_property
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def record_property(request: FixtureRequest):
"""Add an extra properties the calling test.
User properties become part of the test report and are available to the
configured reporters, like JUnit XML.
The fixture is callable with ``(name, value)``, with value being automatically
xml-encoded.
Example::
def test_function(record_property):
record_property("example_key", 1)
"""
_warn_incompatibility_with_xunit2(request, "record_property")
def append_property(name: str, value: object) -> None:
request.node.user_properties.append((name, value))
return append_property
示例6: record_xml_attribute
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def record_xml_attribute(request: FixtureRequest):
"""Add extra xml attributes to the tag for the calling test.
The fixture is callable with ``(name, value)``, with value being
automatically xml-encoded
"""
from _pytest.warning_types import PytestExperimentalApiWarning
request.node.warn(
PytestExperimentalApiWarning("record_xml_attribute is an experimental feature")
)
_warn_incompatibility_with_xunit2(request, "record_xml_attribute")
# Declare noop
def add_attr_noop(name: str, value: str) -> None:
pass
attr_func = add_attr_noop
xml = request.config._store.get(xml_key, None)
if xml is not None:
node_reporter = xml.node_reporter(request.node.nodeid)
attr_func = node_reporter.add_attribute
return attr_func
示例7: _setup_fixtures
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def _setup_fixtures(doctest_item: DoctestItem) -> FixtureRequest:
"""
Used by DoctestTextfile and DoctestItem to setup fixture information.
"""
def func() -> None:
pass
doctest_item.funcargs = {} # type: ignore[attr-defined] # noqa: F821
fm = doctest_item.session._fixturemanager
doctest_item._fixtureinfo = fm.getfixtureinfo( # type: ignore[attr-defined] # noqa: F821
node=doctest_item, func=func, cls=None, funcargs=False
)
fixture_request = FixtureRequest(doctest_item)
fixture_request._fillfixtures()
return fixture_request
示例8: test_request_attributes
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def test_request_attributes(self, testdir):
item = testdir.getitem(
"""
import pytest
@pytest.fixture
def something(request): pass
def test_func(something): pass
"""
)
req = fixtures.FixtureRequest(item)
assert req.function == item.obj
assert req.keywords == item.keywords
assert hasattr(req.module, "test_func")
assert req.cls is None
assert req.function.__name__ == "test_func"
assert req.config == item.config
assert repr(req).find(req.function.__name__) != -1
示例9: test_request_contains_funcarg_arg2fixturedefs
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def test_request_contains_funcarg_arg2fixturedefs(self, testdir):
modcol = testdir.getmodulecol(
"""
import pytest
@pytest.fixture
def something(request):
pass
class TestClass(object):
def test_method(self, something):
pass
"""
)
(item1,) = testdir.genitems([modcol])
assert item1.name == "test_method"
arg2fixturedefs = fixtures.FixtureRequest(item1)._arg2fixturedefs
assert len(arg2fixturedefs) == 1
assert arg2fixturedefs["something"][0].argname == "something"
示例10: test_func_closure_module
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def test_func_closure_module(self, testdir):
testdir.makepyfile(
"""
import pytest
@pytest.fixture(scope='module')
def m1(): pass
@pytest.fixture(scope='function')
def f1(): pass
def test_func(f1, m1):
pass
"""
)
items, _ = testdir.inline_genitems()
request = FixtureRequest(items[0])
assert request.fixturenames == "m1 f1".split()
示例11: _get_details_from_pytest_request
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def _get_details_from_pytest_request(frame):
if FixtureRequest is None:
return
request = frame.f_locals.get("request", None)
if request is None:
return
if request.cls is not None:
class_name = request.cls.__name__
else:
class_name = None
return TestDetails(
file_path=request.fspath.strpath,
class_name=class_name,
test_name=request.function.__name__,
)
示例12: initialise_fixture_attrs
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def initialise_fixture_attrs(self):
# pylint: disable=protected-access,attribute-defined-outside-init
self.funcargs = {}
# _get_direct_parametrize_args checks parametrize arguments in Python
# functions, but we don't care about that in Tavern.
self.session._fixturemanager._get_direct_parametrize_args = lambda _: []
fixtureinfo = self.session._fixturemanager.getfixtureinfo(
self, self.obj, type(self), funcargs=False
)
self._fixtureinfo = fixtureinfo
self.fixturenames = fixtureinfo.names_closure
self._request = fixtures.FixtureRequest(self)
# Hack to stop issue with pytest-rerunfailures
示例13: get_schema
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def get_schema(
*,
request: FixtureRequest,
name: str,
method: Optional[Filter] = None,
endpoint: Optional[Filter] = None,
tag: Optional[Filter] = None,
operation_id: Optional[Filter] = None,
test_function: GenericTest,
hooks: HookDispatcher,
validate_schema: Union[bool, NotSet] = NOT_SET,
) -> BaseSchema:
"""Loads a schema from the fixture."""
# pylint: disable=too-many-arguments
schema = request.getfixturevalue(name)
if not isinstance(schema, BaseSchema):
raise ValueError(f"The given schema must be an instance of BaseSchema, got: {type(schema)}")
return schema.clone(
method=method,
endpoint=endpoint,
tag=tag,
operation_id=operation_id,
test_function=test_function,
hooks=hooks,
validate_schema=validate_schema,
)
示例14: get_fixtures
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def get_fixtures(func: Callable, request: FixtureRequest) -> Dict[str, Any]:
"""Load fixtures, needed for the test function."""
sig = signature(func)
return {name: request.getfixturevalue(name) for name in sig.parameters if name != "case"}
示例15: test_weather_time_programmatic
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import FixtureRequest [as 别名]
def test_weather_time_programmatic(
hour: float,
max_err: float,
weather_env: HolodeckEnvironment,
request: FixtureRequest,
) -> None:
"""Validate that time can be set programmatically by comparing RGB
sensor data with saved baseline data
Args:
hour (:obj:`float`): The hour in 24-hour format: [0, 23].
max_err: Maximum mean squared error between sensor data and baseline
weather_env: Environment fixture shared by programmatic tests
data allowed for test to pass
request: pytest fixture request information
"""
weather_env.weather.set_day_time(hour)
weather_env.tick(5)
err = compare_rgb_sensor_data_with_baseline(
weather_env.tick()["TestCamera"],
request.fspath.dirname,
"weather_time_{}".format(hour),
)
assert err < max_err