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


Python pytest.yield_fixture方法代码示例

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


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

示例1: test_exception_in_observer_is_raised_if_no_result_called_but_decorator_on_method

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import yield_fixture [as 别名]
def test_exception_in_observer_is_raised_if_no_result_called_but_decorator_on_method(do_nothing_connection_observer,
                                                                                     ObserverExceptionClass):
    from moler.util.moler_test import MolerTest
    exc = ObserverExceptionClass("some error inside observer")

    class MyTest(object):
        @MolerTest.raise_background_exceptions()
        # @MolerTest.raise_background_exceptions  # doesn't work since it is created by python and given class as first argument
        #                                               # compare with syntax of @pytest.fixture  @pytest.yield_fixture
        def method_using_observer(self):
            observer = do_nothing_connection_observer
            observer.set_exception(exc)

    with pytest.raises(ExecutionException) as err:
        MyTest().method_using_observer()
    ConnectionObserver.get_unraised_exceptions() 
开发者ID:nokia,项目名称:moler,代码行数:18,代码来源:test_moler_test.py

示例2: pytest_fixture

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import yield_fixture [as 别名]
def pytest_fixture(hook=None, name=None, **kwargs):
        """Generator-aware pytest.fixture decorator for legacy pytest versions"""
        def _decorate(f):
            if name is not None:
                # 'name' argument is not supported in this old version, use the __name__ trick.
                f.__name__ = name

            # call hook if needed
            if hook is not None:
                f = hook(f)

            # create the fixture
            if isgeneratorfunction(f):
                return pytest.yield_fixture(**kwargs)(f)
            else:
                return pytest.fixture(**kwargs)(f)
        return _decorate 
开发者ID:smarie,项目名称:python-pytest-cases,代码行数:19,代码来源:common_pytest.py

示例3: patch

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import yield_fixture [as 别名]
def patch(option, *patches, **kwargs):
    negate = kwargs.get('negate', False)

    @pytest.yield_fixture(autouse=True, scope='session')
    def patch_conditionally(request):
        condition = bool(request.config.getoption(option))
        if negate:
            condition = not condition
        if condition:
            with contextlib.ExitStack() as exit_stack:
                for patch in patches:
                    exit_stack.enter_context(patch)
                yield
        else:
            yield

    return patch_conditionally 
开发者ID:IvanMalison,项目名称:okcupyd,代码行数:19,代码来源:conftest.py

示例4: test_marking_whole_class

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import yield_fixture [as 别名]
def test_marking_whole_class(testdir):
    testdir.makepyfile("""
        import pytest

        has_cassette = False

        @pytest.yield_fixture
        def vcr_cassette(vcr_cassette):
            global has_cassette
            has_cassette = True
            yield vcr_cassette
            has_cassette = False

        @pytest.mark.vcr
        class TestClass(object):
            def test_method(self):
                assert has_cassette
    """)

    result = testdir.runpytest('-s')
    assert result.ret == 0 
开发者ID:ktosiek,项目名称:pytest-vcr,代码行数:23,代码来源:test_vcr.py

示例5: runner

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import yield_fixture [as 别名]
def runner(request):
    def _( ga, **kargs ):
        time.sleep(0.5) # leave the time to shutdown previous instance
        if request.param=="serve":
            return getattr(ga,request.param)(port=10000)
        else:
            return getattr(ga,request.param)(**kargs)

    return _

# @pytest.yield_fixture(scope='session')
# def event_loop(request):
#     """Create an instance of the default event loop for each test case."""
#     loop = asyncio.get_event_loop_policy().new_event_loop()
#     yield loop
#     loop.close() 
开发者ID:manatlan,项目名称:guy,代码行数:18,代码来源:conftest.py

示例6: case_obj

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import yield_fixture [as 别名]
def case_obj(ped_lines):
    """Return a test case object with individuals."""
    _case = get_cases('tests/fixtures/hapmap.vcf', case_lines=ped_lines)[0]
    yield _case

# @pytest.yield_fixture(scope='function')
# def sql_case_obj(case_obj):
#     """Return a test case for the sql model."""
#     _sql_case = SqlCase(case_id=case_obj.case_id,
#                     name=case_obj.name,
#                     variant_source=case_obj.variant_source,
#                     variant_type=case_obj.variant_type,
#                     variant_mode=case_obj.variant_type,
#                     compressed=case_obj.compressed,
#                     tabix_index=case_obj.tabix_index)
#
#     yield _sql_case 
开发者ID:robinandeer,项目名称:puzzle,代码行数:19,代码来源:conftest.py

示例7: test_early_display

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import yield_fixture [as 别名]
def test_early_display(monkeypatch, testdir):
    """Make sure DISPLAY is set in a session-scoped fixture already."""
    monkeypatch.delenv('DISPLAY')
    testdir.makepyfile("""
        import os
        import pytest

        @pytest.yield_fixture(scope='session', autouse=True)
        def fixt():
            assert 'DISPLAY' in os.environ
            yield

        def test_foo():
            pass
    """) 
开发者ID:The-Compiler,项目名称:pytest-xvfb,代码行数:17,代码来源:test_xvfb.py

示例8: response_fixture_factory

# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import yield_fixture [as 别名]
def response_fixture_factory(url, data=None, status=200):
    @pytest.yield_fixture
    def fixture():
        responses.add(
            responses.POST,
            url,
            status=status,
            body=json.dumps(data or {}),
            content_type='application/json',
        )
        responses.start()
        yield responses
        responses.stop()
        responses.reset()
    return fixture 
开发者ID:jmcarp,项目名称:betfair.py,代码行数:17,代码来源:utils.py


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