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


Python tools.with_setup方法代码示例

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


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

示例1: test_nose_setup

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import with_setup [as 别名]
def test_nose_setup(testdir):
    p = testdir.makepyfile(
        """
        values = []
        from nose.tools import with_setup

        @with_setup(lambda: values.append(1), lambda: values.append(2))
        def test_hello():
            assert values == [1]

        def test_world():
            assert values == [1,2]

        test_hello.setup = lambda: values.append(1)
        test_hello.teardown = lambda: values.append(2)
    """
    )
    result = testdir.runpytest(p, "-p", "nose")
    result.assert_outcomes(passed=2) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:21,代码来源:test_nose.py

示例2: test_nose_setup_func_failure

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import with_setup [as 别名]
def test_nose_setup_func_failure(testdir):
    p = testdir.makepyfile(
        """
        from nose.tools import with_setup

        values = []
        my_setup = lambda x: 1
        my_teardown = lambda x: 2

        @with_setup(my_setup, my_teardown)
        def test_hello():
            print(values)
            assert values == [1]

        def test_world():
            print(values)
            assert values == [1,2]

    """
    )
    result = testdir.runpytest(p, "-p", "nose")
    result.stdout.fnmatch_lines(["*TypeError: <lambda>()*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:24,代码来源:test_nose.py

示例3: with_sitl

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import with_setup [as 别名]
def with_sitl(fn):
    @with_setup(setup_sitl, teardown_sitl)
    def test(*args, **kargs):
        return fn('tcp:127.0.0.1:5760', *args, **kargs)
    return test 
开发者ID:dronekit,项目名称:dronekit-python,代码行数:7,代码来源:__init__.py

示例4: test_query_error

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import with_setup [as 别名]
def test_query_error():  # type: () -> None
    Query(123)  # type: ignore


# @with_setup(make_setup_func(), destroy_func)
# def test_save():
#     assert game_scores[0].id 
开发者ID:leancloud,项目名称:python-sdk,代码行数:9,代码来源:test_query.py

示例5: test_and_error

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import with_setup [as 别名]
def test_and_error():  # type: () -> None
    Query(GameScore).and_("score")  # type: ignore


# @with_setup(make_setup_func())
# def test_dump():
#     q = Query(GameScore) 
开发者ID:leancloud,项目名称:python-sdk,代码行数:9,代码来源:test_query.py

示例6: test_nose_setup_func

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import with_setup [as 别名]
def test_nose_setup_func(testdir):
    p = testdir.makepyfile(
        """
        from nose.tools import with_setup

        values = []

        def my_setup():
            a = 1
            values.append(a)

        def my_teardown():
            b = 2
            values.append(b)

        @with_setup(my_setup, my_teardown)
        def test_hello():
            print(values)
            assert values == [1]

        def test_world():
            print(values)
            assert values == [1,2]

    """
    )
    result = testdir.runpytest(p, "-p", "nose")
    result.assert_outcomes(passed=2) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:30,代码来源:test_nose.py

示例7: test_module_level_setup

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import with_setup [as 别名]
def test_module_level_setup(testdir):
    testdir.makepyfile(
        """
        from nose.tools import with_setup
        items = {}

        def setup():
            items[1]=1

        def teardown():
            del items[1]

        def setup2():
            items[2] = 2

        def teardown2():
            del items[2]

        def test_setup_module_setup():
            assert items[1] == 1

        @with_setup(setup2, teardown2)
        def test_local_setup():
            assert items[2] == 2
            assert 1 not in items
    """
    )
    result = testdir.runpytest("-p", "nose")
    result.stdout.fnmatch_lines(["*2 passed*"]) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:31,代码来源:test_nose.py


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