Commit 9f520cda authored by Dom Sekotill's avatar Dom Sekotill
Browse files

changed how test_generators are stored and found

Instead of storing the test_generator in-place of the function it wraps
and later swapping the function back during metaclass processing, the
generator is now stored as an attribute of the function.
parent 8dd697b0
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -88,7 +88,8 @@ class test_generator(object):

	def __call__(self, func):
		self.func = func
		return self
		func.__test_generator__ = self
		return func

	def wrap(self, testcase_class):
		"""
@@ -119,9 +120,6 @@ class test_generator(object):
			wrapper = self._make_wrap(tuple(args), dict(kwds))
			yield 'test_{0}_{1}'.format(wrapper.__name__, number), wrapper

		yield self.func.__name__, self.func
		yield '_test_generator_' + self.func.__name__, self

	def _make_wrap(self, args, kwds):
		@wraps(self.func)
		def wrapper(*a):
@@ -148,7 +146,11 @@ class TestGeneratorMeta(type):

	def __new__(cls, clsname, bases, attr):
		new = super(TestGeneratorMeta, cls).__new__(cls, clsname, bases, attr)
		for name, obj in list(attr.items()):
			if isinstance(obj, test_generator):
				obj.wrap(new)
		for name in dir(new):
			try:
				generator = getattr(new, name).__test_generator__
			except (AttributeError):
				continue
			else:
				generator.wrap(new)
		return new