當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。