本文整理汇总了Python中nose.plugins.attrib.attr函数的典型用法代码示例。如果您正苦于以下问题:Python attr函数的具体用法?Python attr怎么用?Python attr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了attr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:blambov,项目名称:cassandra-dtest,代码行数:10,代码来源:tools.py
示例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
开发者ID:jeffjirsa,项目名称:cassandra-dtest,代码行数:11,代码来源:decorators.py
示例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)
开发者ID:maudineormsby,项目名称:saucelabs-python,代码行数:7,代码来源:sauce_helpers.py
示例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
开发者ID:WorksApplications,项目名称:cassandra-dtest,代码行数:60,代码来源:tools.py
示例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)
开发者ID:FaridGaffoor,项目名称:Flexget,代码行数:35,代码来源:__init__.py
示例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)
开发者ID:LucianU,项目名称:kuma-lib,代码行数:8,代码来源:test_attribute_plugin.py
示例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'])
开发者ID:LucianU,项目名称:kuma-lib,代码行数:8,代码来源:test_attribute_plugin.py
示例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)
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:testing.py
示例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')
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:9,代码来源:test_attribute_plugin.py
示例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)
开发者ID:alfredo,项目名称:make.mozilla.org,代码行数:9,代码来源:decorators.py
示例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)
开发者ID:alfredo,项目名称:make.mozilla.org,代码行数:9,代码来源:decorators.py
示例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)
开发者ID:JerryVerhoef,项目名称:PyGitUp,代码行数:9,代码来源:__init__.py
示例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)
开发者ID:LeBenHL,项目名称:pyexchange,代码行数:13,代码来源:__init__.py
示例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
开发者ID:electroniceagle,项目名称:aloe,代码行数:13,代码来源:testclass.py
示例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
开发者ID:iamaleksey,项目名称:cassandra-dtest,代码行数:16,代码来源:decorators.py
示例16: make_scenario
def make_scenario(cls, scenario, index):
"""
Construct a method running the scenario steps.
index is the 1-based number of the scenario in the feature.
"""
if scenario.outlines:
source = 'def run_outlines(self):\n' + '\n'.join(
' outline{i}(self)'.format(i=i)
for i in range(len(scenario.outlines))
)
source = ast.parse(source)
# Set locations of the steps
for outline, outline_call in \
zip(scenario.outlines, source.body[0].body):
for node in ast.walk(outline_call):
node.lineno = outline.line
context = {
'outline' + str(i): cls.make_steps(scenario,
steps,
is_background=False,
outline=outline)
for i, (outline, steps) in enumerate(scenario.evaluated)
}
result = make_function(
source=source,
context=context,
source_file=scenario.feature.filename,
name=scenario.name,
)
else:
result = cls.make_steps(scenario,
scenario.steps,
is_background=False)
result.is_scenario = True
result.scenario = scenario
result.scenario_index = index
for tag in scenario.tags:
result = attr(tag)(result)
return result
开发者ID:jricardo27,项目名称:aloe,代码行数:47,代码来源:testclass.py
示例17: wip
def wip(fn):
"""
Work-in-progress decorator @wip
This decorator lets you check tests into version control and not gate a push
while allowing you to work on making them pass
- If the test fails it will be skipped
- If the test passes it will report a failure
"""
@wraps(fn)
def run_test(*args, **kwargs):
try:
fn(*args, **kwargs)
except Exception as ex:
raise SkipTest( "WIP FAILURE: %s" % str(ex))
raise AssertionError("Test passed but is work in progress")
return attr('wip')(run_test)
开发者ID:johnmdilley,项目名称:xenrt,代码行数:17,代码来源:testing.py
示例18: test_class_attrs
def test_class_attrs():
# @attr('slow', 'net', role='integration')
class MyTest:
def setUp():
pass
def test_one(self):
pass
def test_two(self):
pass
class SubClass(MyTest):
pass
MyTest = attr('slow', 'net', role='integration')(MyTest)
eq_(MyTest.slow, 1)
eq_(MyTest.net, 1)
eq_(MyTest.role, 'integration')
eq_(SubClass.slow, 1)
assert not hasattr(MyTest.setUp, 'slow')
assert not hasattr(MyTest.test_two, 'slow')
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:21,代码来源:test_attribute_plugin.py
示例19: use_vcr
def use_vcr(func):
"""
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.
"""
module = func.__module__.split('tests.')[-1]
class_name = inspect.stack()[1][3]
cassette_name = '.'.join([module, class_name, func.__name__])
cassette_path, _ = vcr.get_path_and_merged_config(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)
# VCR playback on windows needs a bit of help https://github.com/kevin1024/vcrpy/issues/116
if sys.platform.startswith('win') and vcr.record_mode != 'all' and os.path.exists(cassette_path):
func = mock.patch('requests.packages.urllib3.connectionpool.is_connection_dropped',
new=mock.MagicMock(return_value=False))(func)
@wraps(func)
def func_with_cassette(*args, **kwargs):
with vcr.use_cassette(cassette_name) as cassette:
try:
func(*args, cassette=cassette, **kwargs)
except TypeError:
func(*args, **kwargs)
if VCR_RECORD_MODE == 'off':
return func
else:
return func_with_cassette
开发者ID:H1ghT0p,项目名称:Flexget,代码行数:40,代码来源:__init__.py
示例20: flaky
def flaky(max_runs=None, min_passes=None):
"""
Decorator used to mark a test as "flaky". When used in conjuction with
the flaky nosetests plugin, will cause the decorated test to be retried
until min_passes successes are achieved out of up to max_runs test runs.
:param max_runs:
The maximum number of times the decorated test will be run.
:type max_runs:
`int`
:param min_passes:
The minimum number of times the test must pass to be a success.
:type min_passes:
`int`
:return:
A wrapper function that includes attributes describing the flaky test.
:rtype:
`callable`
"""
if max_runs is None:
max_runs = 2
if min_passes is None:
min_passes = 1
if min_passes <= 0:
raise ValueError('min_passes must be positive')
# In case @flaky is applied to a function or class without arguments
# (and without parentheses), max_runs will refer to the wrapped object.
# In this case, the default value can be used.
wrapped = None
if hasattr(max_runs, '__call__'):
wrapped = max_runs
max_runs = 2
if max_runs < min_passes:
raise ValueError('min_passes cannot be greater than max_runs!')
wrapper = attr(**{
FlakyNames.MAX_RUNS: max_runs,
FlakyNames.MIN_PASSES: min_passes,
FlakyNames.CURRENT_RUNS: 0,
FlakyNames.CURRENT_PASSES: 0,
})
return wrapper(wrapped) if wrapped is not None else wrapper
开发者ID:aptxkid,项目名称:flaky,代码行数:40,代码来源:flaky_decorator.py
注:本文中的nose.plugins.attrib.attr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论