test_tests_utils.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:niceman 作者: ReproNim 项目源码 文件源码
def test_skip_if_no_network():
    cleaned_env = os.environ.copy()
    cleaned_env.pop('NICEMAN_TESTS_NONETWORK', None)
    # we need to run under cleaned env to make sure we actually test in both conditions
    with patch('os.environ', cleaned_env):
        @skip_if_no_network
        def somefunc(a1):
            return a1
        eq_(somefunc.tags, ['network'])
        with patch.dict('os.environ', {'NICEMAN_TESTS_NONETWORK': '1'}):
            assert_raises(SkipTest, somefunc, 1)
        with patch.dict('os.environ', {}):
            eq_(somefunc(1), 1)
        # and now if used as a function, not a decorator
        with patch.dict('os.environ', {'NICEMAN_TESTS_NONETWORK': '1'}):
            assert_raises(SkipTest, skip_if_no_network)
        with patch.dict('os.environ', {}):
            eq_(skip_if_no_network(), None)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号