I've been using DDT to parameterize my tests with great success for the past few months. My issue now is that I can't seem to inject a list variable as my data source. Doing so seems to confuse DDT causing it to not parameterize my tests. I started to create my own solution, but I can't seem to figure this last part out.
Here is what I have thus far as decorators -
def data(*values):
def aaa(func):
def wrapper(self, *args, **kwargs):
pass
# return func(self, *args, **kwargs)
wrapper.func_name = func.__name__ + 't'
wrapper.values = values
return wrapper
return aaa
def c(cls):
for name, method in list(cls.__dict__.items()):
if hasattr(method, 'values'):
for ticket in method.values[0]:
test_name = mk_test_name(method.func_name, ticket)
print(test_name)
setattr(cls, test_name, method(cls, ticket))
return cls
And I use it as such -
@c
class IntegrationTests(APITestCase):
tickets = [1, 2, 3, 4]
@data(tickets)
def tes(self, t):
print(t)
How can I make the Python testing framework recognize that I've added via decorator? I know the methods have been added because issuing the dir
command in PDB displays them. The goal for this is that I would duplicate the test(s) I decorate for each item in a list. For those wondering why wrapper()
has no code, I did this because uncommenting the line the return call causes the method I decorate to be executed without parameters, thus causing an error.
In my example, I would expect 4 tests with different names to be executed.