summaryrefslogtreecommitdiff
path: root/pytest_helpers_namespace/plugin.py
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-11-11 09:57:22 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-11-11 09:57:22 -0700
commit4425df5d5829f3e82661903863d0884e493485b3 (patch)
tree66fef08882bae6676c7fdbb09e3d68ab456e4ac1 /pytest_helpers_namespace/plugin.py
parentcd1ea7b6bfb59c8c89c4eb22908657f027829c1a (diff)
parent30a004ac7fcd4db3f8abe6e825bb64d6ec67c179 (diff)
record new upstream branch created by importing pytest-helpers-namespace_2017.11.11.orig.tar.gz and merge it
Diffstat (limited to 'pytest_helpers_namespace/plugin.py')
-rw-r--r--pytest_helpers_namespace/plugin.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/pytest_helpers_namespace/plugin.py b/pytest_helpers_namespace/plugin.py
index 729036b..95ab3e5 100644
--- a/pytest_helpers_namespace/plugin.py
+++ b/pytest_helpers_namespace/plugin.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
- :copyright: © 2016 by the SaltStack Team, see AUTHORS for more details.
+ :copyright: © 2016-2017 by the SaltStack Team, see AUTHORS for more details.
:license: Apache 2.0, see LICENSE for more details.
@@ -12,7 +12,8 @@
'''
# Import python libs
-from functools import wraps
+from functools import partial, wraps
+
class FuncWrapper(object):
@@ -53,17 +54,22 @@ class HelpersRegistry(object):
def __init__(self):
self._registry = {}
- def register(self, func):
+ def register(self, func, name=None):
'''
Register's a new function as a helper
'''
- if func.__name__ in self._registry:
+ if isinstance(func, str):
+ return partial(self.register, name=func)
+
+ if name is None:
+ name = func.__name__
+ if name in self._registry:
raise RuntimeError(
'A helper function is already registered under the name: {0}'.format(
- func.__name__
+ name
)
)
- self._registry[func.__name__] = wraps(func)(FuncWrapper(func))
+ self._registry[name] = wraps(func)(FuncWrapper(func))
return func
def __getattribute__(self, name):