python类with_setup()的实例源码

pubsub_tests.py 文件源码 项目:birdseye-server 作者: DramaticLiberty 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def teardown(self):
        pass

    # @nt.with_setup(setup, teardown)
    # def test_publish_as_configured(self):
    #     data = _randstr()
    #     nt.set_trace()
    #     ps.publish(data)
    #     mockpn.publish.assert_called_once()

    # @nt.with_setup(setup, teardown)
    # def test_publish_custom_channels(self):
    #     data = _randstr()
    #     ch = _make_channel('testChan2')
    #     self.pubsub.publish(data, channels=ch)
    #     chs = [_make_channel('testChan2'), _make_channel('testChan2')]
    #     self.pubsub.publish(data, channels=chs)
        #nt.assert_in(data, self.listener.messages)
test_nose.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_nose_setup(testdir):
    p = testdir.makepyfile("""
        l = []
        from nose.tools import with_setup

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

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

        test_hello.setup = lambda: l.append(1)
        test_hello.teardown = lambda: l.append(2)
    """)
    result = testdir.runpytest(p, '-p', 'nose')
    result.assert_outcomes(passed=2)
test_nose.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_nose_setup_func_failure(testdir):
    p = testdir.makepyfile("""
        from nose.tools import with_setup

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

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

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

    """)
    result = testdir.runpytest(p, '-p', 'nose')
    result.stdout.fnmatch_lines([
        "*TypeError: <lambda>()*"
    ])
test_nose.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_nose_setup_func(testdir):
    p = testdir.makepyfile("""
        from nose.tools import with_setup

        l = []

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

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

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

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

    """)
    result = testdir.runpytest(p, '-p', 'nose')
    result.assert_outcomes(passed=2)
test_nose.py 文件源码 项目:GSM-scanner 作者: yosriayed 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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*",
    ])


问题


面经


文章

微信
公众号

扫码关注公众号