本文整理汇总了Python中nose.plugins.attrib.attr函数的典型用法代码示例。如果您正苦于以下问题:Python attr函数的具体用法?Python attr怎么用?Python attr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了attr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrapper
def wrapper(f):
assert failure_source in valid_failure_sources
assert isinstance(flaky, bool)
tagged_func = attr(known_failure=failure_source, jira_url=jira_url)(f)
if flaky:
tagged_func = attr("known_flaky")(tagged_func)
if notes:
tagged_func = attr(failure_notes=notes)(tagged_func)
return tagged_func
示例2: wrapper
def wrapper(f):
assert_in(failure_source, valid_failure_sources)
assert_is_instance(flaky, bool)
tagged_func = attr(known_failure=failure_source,
jira_url=jira_url)(f)
if flaky:
tagged_func = attr('known_flaky')(tagged_func)
tagged_func = attr(failure_notes=notes)(tagged_func)
return tagged_func
示例3: travis_only
def travis_only(func):
@functools.wraps(func)
def run_test(*args, **kwargs):
if not travis:
raise SkipTest('Tunnel tests are run in travis-ci only.')
func(*args, **kwargs)
return attr('travis_only')(run_test)
示例4: require
def require(require_pattern, broken_in=None):
"""Skips the decorated class or method, unless the argument
'require_pattern' is a case-insensitive regex match for the name of the git
branch in the directory from which Cassandra is running. For example, the
method defined here:
@require('compaction-fixes')
def compaction_test(self):
...
will run if Cassandra is running from a directory whose current git branch
is named 'compaction-fixes'. If 'require_pattern' were
'.*compaction-fixes.*', it would run only when Cassandra is being run from a
branch whose name contains 'compaction-fixes'.
To accommodate current branch-naming conventions, it also will run if the
current Cassandra branch matches 'CASSANDRA-{require_pattern}'. This allows
users to run tests like:
@require(4200)
class TestNewFeature(self):
...
on branches named 'CASSANDRA-4200'.
If neither 'require_pattern' nor 'CASSANDRA-{require_pattern}' is a
case-insensitive match for the name of Cassandra's current git branch, the
test function or class will be skipped with unittest.skip.
To run decorated methods as if they were not decorated with @require, set
the environment variable IGNORE_REQUIRE to 'yes' or 'true'. To only run
methods decorated with require, set IGNORE_REQUIRE to 'yes' or 'true' and
run `nosetests` with `-a required`. (This uses the built-in `attrib`
plugin.)
"""
tagging_decorator = attr('required')
if IGNORE_REQUIRE:
return tagging_decorator
require_pattern = str(require_pattern)
git_branch = ''
git_branch = cassandra_git_branch()
if git_branch:
git_branch = git_branch.lower()
run_on_branch_patterns = (require_pattern, 'cassandra-{b}'.format(b=require_pattern))
# always run the test if the git branch name matches
if any(re.match(p, git_branch, re.IGNORECASE) for p in run_on_branch_patterns):
return tagging_decorator
# if skipping a buggy/flapping test, use since
elif broken_in:
def tag_and_skip_after_version(decorated):
return since('0', broken_in)(tagging_decorator(decorated))
return tag_and_skip_after_version
# otherwise, skip with a message
else:
def tag_and_skip(decorated):
return unittest.skip('require ' + str(require_pattern))(tagging_decorator(decorated))
return tag_and_skip
else:
return tagging_decorator
示例5: use_vcr
def use_vcr(func=None, **kwargs):
"""
Decorator for test functions which go online. A vcr cassette will automatically be created and used to capture and
play back online interactions. The nose 'vcr' attribute will be set, and the nose 'online' attribute will be set on
it based on whether it might go online.
The record mode of VCR can be set using the VCR_RECORD_MODE environment variable when running tests. Depending on
the record mode, and the existence of an already recorded cassette, this decorator will also dynamically set the
nose 'online' attribute.
Keyword arguments to :func:`vcr.VCR.use_cassette` can be supplied.
"""
if func is None:
# When called with kwargs, e.g. @use_vcr(inject_cassette=True)
return functools.partial(use_vcr, **kwargs)
module = func.__module__.split('tests.')[-1]
class_name = inspect.stack()[1][3]
cassette_name = '.'.join([module, class_name, func.__name__])
kwargs.setdefault('path', cassette_name)
cassette_path = os.path.join(VCR_CASSETTE_DIR, cassette_name)
online = True
# Set our nose online attribute based on the VCR record mode
if vcr.record_mode == 'none':
online = False
elif vcr.record_mode == 'once':
online = not os.path.exists(cassette_path)
func = attr(online=online, vcr=True)(func)
# If we are not going online, disable domain delay during test
if not online:
func = mock.patch('flexget.utils.requests.wait_for_domain', new=mock.MagicMock())(func)
if VCR_RECORD_MODE == 'off':
return func
else:
return vcr.use_cassette(**kwargs)(func)
示例6: test_flags
def test_flags():
# @attr('one','two')
def test():
pass
test = attr('one','two')(test)
eq_(test.one, 1)
eq_(test.two, 1)
示例7: test_values
def test_values():
# @attr(mood="hohum", colors=['red','blue'])
def test():
pass
test = attr(mood="hohum", colors=['red','blue'])(test)
eq_(test.mood, "hohum")
eq_(test.colors, ['red','blue'])
示例8: wip
def wip(func):
@functools.wraps(func)
def run_test(*args, **kwargs):
try:
func(*args, **kwargs)
except Exception as e:
raise SkipTest("WIP test failed: " + str(e))
assert False, "test passed but marked as work in progress"
return attr('wip')(run_test)
示例9: test_mixed
def test_mixed():
# @attr('slow', 'net', role='integration')
def test():
pass
test = attr('slow', 'net', role='integration')(test)
eq_(test.slow, 1)
eq_(test.net, 1)
eq_(test.role, 'integration')
示例10: integration
def integration(f):
@wraps(f)
def run_test(*args, **kwargs):
integration_run = (os.getenv('INTEGRATION', None) is not None)
if integration_run:
f(*args, **kwargs)
else:
raise SkipTest("Skipping integration test")
return attr('integration')(run_test)
示例11: wip
def wip(f):
@wraps(f)
def run_test(*args, **kwargs):
try:
f(*args, **kwargs)
except Exception as e:
raise SkipTest("WIP test failed: " + str(e))
fail("test passed but marked as work in progress")
return attr('wip')(run_test)
示例12: wip
def wip(f):
@wraps(f)
def run_test(*args, **kwargs):
try:
f(*args, **kwargs)
except Exception as e:
raise SkipTest("WIP test failed: " + str(e))
raise AssertionError("Passing test marked as WIP")
return attr('wip')(run_test)
示例13: wip
def wip(f):
"""
Use this as a decorator to mark tests that are "works in progress"
"""
@wraps(f)
def run_test(*args, **kwargs):
try:
f(*args, **kwargs)
except Exception as e:
raise SkipTest("WIP test failed: " + str(e))
fail("test passed but marked as work in progress")
return attr('wip')(run_test)
示例14: make_example
def make_example(cls, method, scenario, index):
"""
Set the method attributes to associate it with given scenario and index.
"""
method.is_example = True
method.scenario = scenario
method.scenario_index = index
for tag in scenario.tags:
method = attr(tag)(method)
return method
示例15: wrapper
def wrapper(f):
assert_in(failure_source, valid_failure_sources)
assert_is_instance(flaky, bool)
try:
existing_failure_annotations = f.known_failure
except AttributeError:
existing_failure_annotations = []
new_annotation = [{'failure_source': failure_source, 'jira_url': jira_url, 'notes': notes, 'flaky': flaky}]
failure_annotations = existing_failure_annotations + new_annotation
tagged_func = attr(known_failure=failure_annotations)(f)
return tagged_func