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)
评论列表
文章目录