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