本文整理汇总了Python中_pytest.fixtures.SubRequest方法的典型用法代码示例。如果您正苦于以下问题:Python fixtures.SubRequest方法的具体用法?Python fixtures.SubRequest怎么用?Python fixtures.SubRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_pytest.fixtures
的用法示例。
在下文中一共展示了fixtures.SubRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dcos_node
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def dcos_node(request: SubRequest) -> Iterator[Node]:
"""
Return a ``Node``.
This is module scoped as we do not intend to modify the cluster in ways
that make tests interfere with one another.
"""
# We use the Docker backend because it is currently the only one which
# supports all transports.
cluster_backend = Docker(transport=request.param)
with Cluster(
cluster_backend=cluster_backend,
masters=1,
agents=0,
public_agents=0,
) as cluster:
(master, ) = cluster.masters
yield master
示例2: three_master_cluster
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def three_master_cluster(
artifact_path: Path,
docker_backend: Docker,
request: SubRequest,
log_dir: Path,
) -> Generator[Cluster, None, None]:
"""Spin up a highly-available DC/OS cluster with three master nodes."""
with Cluster(
cluster_backend=docker_backend,
masters=3,
agents=0,
public_agents=0,
) as cluster:
cluster.install_dcos_from_path(
dcos_installer=artifact_path,
dcos_config=cluster.base_config,
ip_detect_path=docker_backend.ip_detect_path,
)
wait_for_dcos_oss(
cluster=cluster,
request=request,
log_dir=log_dir,
)
yield cluster
示例3: test_snapshot_backup_and_restore
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def test_snapshot_backup_and_restore(
self,
three_master_cluster: Cluster,
etcd_client: EtcdClient,
tmp_path: Path,
request: SubRequest,
log_dir: Path,
) -> None:
test_key, test_val = "foo", "bar"
etcd_client.put(test_key, test_val)
random = uuid.uuid4().hex
backup_name = "etcd-backup-{random}.tar.gz".format(random=random)
backup_local_path = tmp_path / backup_name
# Take etcd backup from one master node.
_do_backup(next(iter(three_master_cluster.masters)), backup_local_path)
# Restore etcd from backup on all master nodes.
_do_restore(three_master_cluster.masters, backup_local_path)
# assert all etcd containers
for master in three_master_cluster.masters:
assert etcd_client.get_key_from_node(test_key, master) == test_val
示例4: assignmentWithSubmissionWithMarks
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def assignmentWithSubmissionWithMarks(assignmentWithSubmissionNoMarks: Gradebook, request: SubRequest) -> Gradebook:
a = assignmentWithSubmissionNoMarks
g1 = a.find_grade("grade_code1", "p1", "foo", "bitdiddle")
g2 = a.find_grade("grade_code2", "p1", "foo", "bitdiddle")
g3 = a.find_grade("grade_written1", "p1", "foo", "hacker123")
g4 = a.find_grade("grade_written2", "p1", "foo", "hacker123")
g5 = a.find_grade("task1", "p1", "foo", "bitdiddle")
g6 = a.find_grade("task2", "p1", "foo", "bitdiddle")
g7 = a.find_grade("task1", "p1", "foo", "hacker123")
g8 = a.find_grade("task2", "p1", "foo", "hacker123")
(g1.manual_score, g2.manual_score, g3.manual_score, g4.manual_score, g5.manual_score,
g6.manual_score, g7.manual_score, g8.manual_score) = request.param
a.db.commit()
a.usedgrades = request.param
a.usedgrades_code = request.param[:2]
a.usedgrades_written = request.param[2:4]
a.usedgrades_task = request.param[4:]
return a
示例5: pytest_fixture_setup
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def pytest_fixture_setup(
fixturedef: "FixtureDef", request: "SubRequest"
) -> Optional[object]:
"""Performs fixture setup execution.
:return: The return value of the call to the fixture function.
Stops at first non-None result, see :ref:`firstresult`.
.. note::
If the fixture function returns None, other implementations of
this hook function will continue to be called, according to the
behavior of the :ref:`firstresult` option.
"""
示例6: pytest_fixture_post_finalizer
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def pytest_fixture_post_finalizer(
fixturedef: "FixtureDef", request: "SubRequest"
) -> None:
"""Called after fixture teardown, but before the cache is cleared, so
the fixture result ``fixturedef.cached_result`` is still available (not
``None``)."""
# -------------------------------------------------------------------------
# test session related hooks
# -------------------------------------------------------------------------
示例7: __init__
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def __init__(self, captureclass, request: SubRequest) -> None:
self.captureclass = captureclass
self.request = request
self._capture = None # type: Optional[MultiCapture]
self._captured_out = self.captureclass.EMPTY_BUFFER
self._captured_err = self.captureclass.EMPTY_BUFFER
示例8: capsys
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def capsys(request: SubRequest):
"""Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.
The captured output is made available via ``capsys.readouterr()`` method
calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``text`` objects.
"""
capman = request.config.pluginmanager.getplugin("capturemanager")
capture_fixture = CaptureFixture(SysCapture, request)
capman.set_fixture(capture_fixture)
capture_fixture._start()
yield capture_fixture
capture_fixture.close()
capman.unset_fixture()
示例9: capsysbinary
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def capsysbinary(request: SubRequest):
"""Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.
The captured output is made available via ``capsysbinary.readouterr()``
method calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``bytes`` objects.
"""
capman = request.config.pluginmanager.getplugin("capturemanager")
capture_fixture = CaptureFixture(SysCaptureBinary, request)
capman.set_fixture(capture_fixture)
capture_fixture._start()
yield capture_fixture
capture_fixture.close()
capman.unset_fixture()
示例10: capfdbinary
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def capfdbinary(request: SubRequest):
"""Enable bytes capturing of writes to file descriptors ``1`` and ``2``.
The captured output is made available via ``capfd.readouterr()`` method
calls, which return a ``(out, err)`` namedtuple.
``out`` and ``err`` will be ``byte`` objects.
"""
capman = request.config.pluginmanager.getplugin("capturemanager")
capture_fixture = CaptureFixture(FDCaptureBinary, request)
capman.set_fixture(capture_fixture)
capture_fixture._start()
yield capture_fixture
capture_fixture.close()
capman.unset_fixture()
示例11: api_key
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def api_key(request: SubRequest) -> str: # type: ignore
try:
return str(request.config.getoption("--stripe-secret-key"))
except ValueError:
pytest.skip()
示例12: inserted_payment
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def inserted_payment(request: SubRequest, connection: Connection) -> dict:
status = getattr(request, "param", None) or PaymentStatus.NEW.value
charge_id = None if status not in (PaymentStatus.CHARGED.value, PaymentStatus.CAPTURED.value) else "token"
data: Dict[str, Any] = {
"uuid": str(uuid.uuid4()),
"customer_id": 1,
"amount": 100,
"currency": "USD",
"status": status,
"description": "irrelevant",
"charge_id": charge_id,
}
connection.execute(payments.insert(data))
return data
示例13: calico_ipip_cluster
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def calico_ipip_cluster(docker_backend: Docker, artifact_path: Path,
request: SubRequest, log_dir: Path) -> Iterator[Cluster]:
with Cluster(
cluster_backend=docker_backend,
masters=1,
agents=2,
public_agents=1,
) as cluster:
config = {
"superuser_username": superuser_username,
# We can hash the password with any `passlib`-based method here.
# We choose `sha512_crypt` arbitrarily.
"superuser_password_hash": sha512_crypt.hash(superuser_password),
"calico_vxlan_enabled": "false",
"calico_network_cidr": "192.168.128.0/17",
}
cluster.install_dcos_from_path(
dcos_installer=artifact_path,
dcos_config={
**cluster.base_config,
**config,
},
output=Output.LOG_AND_CAPTURE,
ip_detect_path=docker_backend.ip_detect_path,
)
wait_for_dcos_oss(
cluster=cluster,
request=request,
log_dir=log_dir,
)
yield cluster
示例14: three_master_cluster
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def three_master_cluster(
artifact_path: Path,
docker_backend: Docker,
request: SubRequest,
log_dir: Path,
) -> Cluster:
"""
Spin up a highly-available DC/OS cluster with three master nodes.
"""
with Cluster(
cluster_backend=docker_backend,
masters=3,
agents=0,
public_agents=0,
) as cluster:
cluster.install_dcos_from_path(
dcos_installer=artifact_path,
dcos_config=cluster.base_config,
ip_detect_path=docker_backend.ip_detect_path,
output=Output.LOG_AND_CAPTURE,
)
wait_for_dcos_oss(
cluster=cluster,
request=request,
log_dir=log_dir,
)
yield cluster
示例15: test_transaction_log_backup_and_restore
# 需要导入模块: from _pytest import fixtures [as 别名]
# 或者: from _pytest.fixtures import SubRequest [as 别名]
def test_transaction_log_backup_and_restore(
self,
three_master_cluster: Cluster,
zk_client: KazooClient,
tmp_path: Path,
request: SubRequest,
log_dir: Path,
) -> None:
"""
In a 3-master cluster, backing up the transaction log of ZooKeeper on
one node and restoring from the backup on all master results in a
functioning DC/OS cluster with previously backed up Znodes restored.
"""
# Write to ZooKeeper before backup
persistent_flag = _zk_set_flag(zk_client)
ephemeral_flag = _zk_set_flag(zk_client, ephemeral=True)
random = uuid.uuid4().hex
backup_name = 'zk-backup-{random}.tar.gz'.format(random=random)
backup_local_path = tmp_path / backup_name
# Take ZooKeeper backup from one master node.
_do_backup(next(iter(three_master_cluster.masters)), backup_local_path)
# Store a datapoint which we expect to get lost.
not_backed_up_flag = _zk_set_flag(zk_client)
# Restore ZooKeeper from backup on all master nodes.
_do_restore(three_master_cluster.masters, backup_local_path)
# Read from ZooKeeper after restore
assert _zk_flag_exists(zk_client, persistent_flag)
assert _zk_flag_exists(zk_client, ephemeral_flag)
assert not _zk_flag_exists(zk_client, not_backed_up_flag)
# Assert that DC/OS is intact.
wait_for_dcos_oss(
cluster=three_master_cluster,
request=request,
log_dir=log_dir,
)