当前位置: 首页>>代码示例>>Python>>正文


Python pytest.yield_fixture函数代码示例

本文整理汇总了Python中pytest.yield_fixture函数的典型用法代码示例。如果您正苦于以下问题:Python yield_fixture函数的具体用法?Python yield_fixture怎么用?Python yield_fixture使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了yield_fixture函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ids_yield_fixture

def ids_yield_fixture(scope, params, autouse=False):
    return pytest.yield_fixture(
        scope=scope, 
        ids=list(map(lambda i: i[0], params)), 
        params=list(map(lambda i: i[1], params)),  
        autouse=autouse
    )
开发者ID:DenisMinec,项目名称:autotest-snippets,代码行数:7,代码来源:fixtures.py

示例2: set_parameters_fixture

def set_parameters_fixture(paramname, values, key=lambda x: x):
    """Return a fixture that sets and resets a global parameter
    to each of a list of values before and after each test run.
    Allows paramname="foo.bar.var" meaning parameters["foo"]["bar"]["var"].

    Usage:
        repr = set_parameters_fixture("form_compiler.representation", ["quadrature", "uflacs"])
        my_fixture1 = set_parameters_fixture("linear_algebra_backend", ["PETSc", "STL"])
        my_fixture2 = set_parameters_fixture("linear_algebra_backend", [("Eigen", ""), ("STL", "")], key=lambda x: x[0])

        def test_something0(repr):
            assert repr in ("quadrature", "uflacs")
            assert parameters["form_compiler"]["representation"] == repr

        def test_something1(my_fixture1):
            assert my_fixture1 in ("PETSc", "STL")
            assert parameters["linear_algebra_backend"] == my_fixture1

        def test_something2(my_fixture2):
            assert my_fixture2[0] in ("Eigen", "STL")
            assert parameters["linear_algebra_backend"] == my_fixture2[0]

    Try it and see.
    """
    global parameters
    def _pushpop(request):
        gc_barrier()
        if '.' in paramname:
            names = paramname.split('.')
            if len(names) == 2:
                prev = parameters[names[0]][names[1]]                # Remember original value
                parameters[names[0]][names[1]] = key(request.param)  # Set value
                yield request.param                                  # Let test run
                parameters[names[0]][names[1]] = prev                # Reset value
            elif len(names) == 3:
                prev = parameters[names[0]][names[1]][names[2]]                # Remember original value
                parameters[names[0]][names[1]][names[2]] = key(request.param)  # Set value
                yield request.param                                            # Let test run
                parameters[names[0]][names[1]][names[2]] = prev                # Reset value
        else:
            prev = parameters[paramname]               # Remember original value
            parameters[paramname] = key(request.param) # Set value
            yield request.param                        # Let test run
            parameters[paramname] = prev               # Reset value

    return pytest.yield_fixture(scope="function", params=values)(_pushpop)
开发者ID:vincentqb,项目名称:dolfin,代码行数:46,代码来源:fixtures.py

示例3: set_admin_auth

        'maintenance': {
            'maintenance_project': 'maintenance',
            # Keystone url acts as dummy for posting
            'url': 'http://127.0.0.1:9999/test/'
        }
    })
    config.load_extensions()


fresh_database = pytest.fixture(fresh_database)
additional_database = pytest.fixture(additional_db)
fail_on_log_warnings = pytest.fixture(fail_on_log_warnings)
server_init = pytest.fixture(server_init)


with_request_context = pytest.yield_fixture(with_request_context)


@pytest.fixture
def set_admin_auth():
    """Set admin auth for all calls"""
    get_auth_backend().set_admin(True)


@pytest.fixture
def maintenance_proj_init():
    """Create maintenance project."""
    api.project_create('maintenance')


def new_node(name):
开发者ID:CCI-MOC,项目名称:hil,代码行数:31,代码来源:maintenance-pool.py

示例4: test_import_bloggers

from ironblogger.tasks import import_bloggers, export_bloggers
from ironblogger.model import Blogger
from ironblogger.date import now
from six.moves import StringIO
from datetime import datetime
from random import Random
from tests.util import fresh_context
from pprint import pformat
from .util.example_data import databases as example_databases
from .util.randomize import random_database
import arrow
import pytest
import json
import difflib

fresh_context = pytest.yield_fixture(autouse=True)(fresh_context)

legacy_yaml = """
alice:
    links:
        - [Fun With Crypto, "http://example.com/alice/blog.html", "http://example.com/alice/rss.xml"]
    start: 2015-04-01
bob:
    links:
        - [Secret Messages, "http://example.com/bob/secrets/blog.html", "http://example.com/bob/secrets/feed"]
        - [Kittens, "http://example.com/bob/kittens", "http://example.com/bob/kittens/feed.atom"]
    start: 2015-04-08
"""


def test_import_bloggers():
开发者ID:zenhack,项目名称:iron-blogger2,代码行数:31,代码来源:test_task_import_export.py

示例5: setup

# -*- coding: utf-8 -*-

from __future__ import absolute_import

import mock
import pytest

from django.conf import settings

from nplusone.ext.django import setup_state
from tests.utils import calls  # noqa
pytest.yield_fixture(calls)

from . import models


@pytest.fixture(scope='module', autouse=True)
def setup():
    setup_state()


@pytest.fixture
def objects():
    user = models.User.objects.create()
    pet = models.Pet.objects.create(user=user)
    allergy = models.Allergy.objects.create()
    allergy.pets.add(pet)
    occupation = models.Occupation.objects.create(user=user)
    address = models.Address.objects.create(user=user)
    hobby = models.Hobby.objects.create()
    user.hobbies.add(hobby)
开发者ID:pombredanne,项目名称:nplusone,代码行数:31,代码来源:tests.py

示例6: map_interfaces

#    License for the specific language governing permissions and limitations
#    under the License.

import json
import logging

import pytest

from mos_tests import conftest
from mos_tests.environment import devops_client
from mos_tests.functions import common
from mos_tests.ironic import testutils

logger = logging.getLogger(__name__)

make_image = pytest.yield_fixture(scope='class')(testutils.make_image)


def map_interfaces(devops_env, fuel_node):
    """Return pairs of fuel_node interfaces and devops interfaces"""
    pairs = []
    devops_node = devops_env.get_node_by_fuel_node(fuel_node)
    for fuel_interface in fuel_node.get_attribute('interfaces'):
        for devops_interface in devops_node.interfaces:
            if fuel_interface['mac'] == devops_interface.mac_address:
                pairs.append((fuel_interface, devops_interface))
                continue
    return pairs


def remove_ceph_from_node(remote):
开发者ID:Mirantis,项目名称:mos-integration-tests,代码行数:31,代码来源:scale_test.py

示例7: map_interfaces

#    License for the specific language governing permissions and limitations
#    under the License.

import json
import logging

import pytest

from mos_tests import conftest
from mos_tests.environment import devops_client
from mos_tests.functions import common
from mos_tests.ironic import testutils

logger = logging.getLogger(__name__)

ubuntu_image = pytest.yield_fixture(scope='class')(testutils.ubuntu_image)


def map_interfaces(devops_env, fuel_node):
    """Return pairs of fuel_node interfaces and devops interfaces"""
    pairs = []
    devops_node = devops_env.get_node_by_fuel_node(fuel_node)
    for fuel_interface in fuel_node.get_attribute('interfaces'):
        for devops_interface in devops_node.interfaces:
            if fuel_interface['mac'] == devops_interface.mac_address:
                pairs.append((fuel_interface, devops_interface))
                continue
    return pairs


def remove_ceph_from_node(remote):
开发者ID:SergeySokolov,项目名称:mos-integration-tests,代码行数:31,代码来源:scale_test.py

示例8: enumerate

    flavors = []
    for i, config in enumerate(ironic_drivers_params):
        flavor = os_conn.nova.flavors.create(
            name='baremetal_{}'.format(i),
            ram=config['node_properties']['memory_mb'],
            vcpus=config['node_properties']['cpus'],
            disk=config['node_properties']['local_gb'])
        flavors.append(flavor)

    yield flavors

    for flavor in flavors:
        flavor.delete()


ubuntu_image = pytest.yield_fixture()(testutils.ubuntu_image)


def make_ironic_node(config, devops_env, ironic, name, fuel_env):

    baremetal_interface = devops_env.get_interface_by_fuel_name('baremetal',
                                                                fuel_env)
    baremetal_net_name = baremetal_interface.network.name

    devops_node = None
    if config['driver'] == 'fuel_libvirt':
        devops_node = devops_env.add_node(
            name=name,
            vcpu=config['node_properties']['cpus'],
            memory=config['node_properties']['memory_mb'],
            disks=[config['node_properties']['local_gb']],
开发者ID:AlexandraAllakhverdieva,项目名称:mos-integration-tests,代码行数:31,代码来源:conftest.py

示例9: class_teardown

def class_teardown(func):
    def teardown_(*args, **kwargs):
        yield
        func(*args, **kwargs)
    return pytest.yield_fixture(autouse=True, scope='class')(teardown_)
开发者ID:Yelp,项目名称:Tron,代码行数:5,代码来源:fixtures.py

示例10: import

"""test_level3_dithers: Test of dither rules."""
from __future__ import absolute_import
import pytest

from .helpers import (
    generate_params,
    generate_pool_paths,
    mkstemp_pool_file,
    t_path
)

from ..main import Main

pool_path = pytest.yield_fixture(
    scope='module',
    params=['data/pool_001_candidates.csv']
)(generate_pool_paths)


pool_params = pytest.fixture(
    scope='module',
    params=[
        # Invalid ACID
        (
            ['-i', 'nosuchid'],
            0
        ),
        # Basic observation ACIDs
        (
            ['-i', 'o001'],
            2
开发者ID:philhodge,项目名称:jwst,代码行数:31,代码来源:test_level3_candidates.py

示例11: class_setup_teardown

def class_setup_teardown(func):
    return pytest.yield_fixture(autouse=True, scope='class')(func)
开发者ID:Yelp,项目名称:Tron,代码行数:2,代码来源:fixtures.py

示例12: teardown

def teardown(func):
    def teardown_(*args, **kwargs):
        yield
        func(*args, **kwargs)
    return pytest.yield_fixture(autouse=True)(teardown_)
开发者ID:Yelp,项目名称:Tron,代码行数:5,代码来源:fixtures.py

示例13: setup_teardown

def setup_teardown(func):
    return pytest.yield_fixture(autouse=True)(func)
开发者ID:Yelp,项目名称:Tron,代码行数:2,代码来源:fixtures.py

示例14: enumerate

    flavors = []
    for i, config in enumerate(ironic_drivers_params):
        flavor = os_conn.nova.flavors.create(
            name='baremetal_{}'.format(i),
            ram=config['node_properties']['memory_mb'],
            vcpus=config['node_properties']['cpus'],
            disk=config['node_properties']['local_gb'])
        flavors.append(flavor)

    yield flavors

    for flavor in flavors:
        flavor.delete()


make_image = pytest.yield_fixture()(testutils.make_image)


def make_devops_node(config, devops_env, fuel_env, name):
    """Creates devops ironic_slave node"""
    baremetal_interface = devops_env.get_interface_by_fuel_name('baremetal',
                                                                fuel_env)
    baremetal_net_name = baremetal_interface.network.name

    devops_node = devops_env.add_node(
        name=name,
        vcpu=config['node_properties']['cpus'],
        memory=config['node_properties']['memory_mb'],
        disks=[config['node_properties']['local_gb']],
        networks=[baremetal_net_name],
        role='ironic_slave')
开发者ID:Mirantis,项目名称:mos-integration-tests,代码行数:31,代码来源:conftest.py

示例15: gendata

def gendata(length):
    return tuple(
        DataObject(
            ref=rndstr(5, 20),
            data={
                rndstr(5, 20): rndstr(0, 25)
                for _ in range(random.randint(0, 25))
            }
        )
        for _ in range(length)
    )


available_backends = [backend for backend in get_backends() if backend.is_connected()]
backend_fixture = pytest.yield_fixture(params=available_backends, ids=[backend.__name__ for backend in available_backends])


def _backend(request):
    backend = request.param
    request.applymarker(getattr(pytest.mark, backend.__name__)())
    inst = backend(**backend.settings_for('test', 'test', request.fixturename))
    yield inst
    inst.unset_all()


def backend():
    return types.FunctionType(
        _backend.__code__,
        _backend.__globals__,
        name=_backend.__name__,
开发者ID:CenterForOpenScience,项目名称:jamdb,代码行数:30,代码来源:conftest.py


注:本文中的pytest.yield_fixture函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。