Note that there are some explanatory texts on larger screens.

plurals
  1. POpython dynamic test generation
    primarykey
    data
    text
    <p>I've a base class that yields test cases. Concrete implementations of the class register tests. Since nose only supports test generation via yield for test functions (not classes) I want a class decorator that applies the necessary function wrapping.</p> <p>NOTE: the reason why I need to yield test cases is that the test class needs to do some initialization that cannot be run in setUp.</p> <p>Below is a minimal example that shows the expected behavior, however, it only works if the <code>make_generator</code> decorator is <strong>in</strong> the current module - when I move it to a separate module no tests are yielded. Can anybody tell me why this happens?</p> <pre><code>def make_generator(cls): """returns a function that instantiates ``cls`` and yields tests. """ def generator(): obj = cls() for t in obj: yield t generator.__name__ = 'test_%s' % cls.__name__ return generator def register(func): """Set _check attr of ``func``. """ func._check = True return func class BaseMixin(object): def __init__(self): """Register check handlers. """ self.check_handlers = [] attrs = (attr for attr in dir(self) if not attr.startswith('__')) for attr in attrs: func = getattr(self, attr) if getattr(func, '_check', False): self.check_handlers.append(attr) def __iter__(self): """Generate tests for registered handlers. """ # do stuff args = [] for check in self.check_handlers: func = getattr(self, check) yield func, args @make_generator class ConcreteTest(BaseMixin): @register def check_foobar(self, args): assert False </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload