NOT VALID! Unittest is not run when it has a decorator

102 views Asked by At

EDIT: As I've answered below this question is not valid since it was all a misunderstanding on my behalf.

I have made a try-except decorator for custom errors and I want to apply this decorator on my unit tests. However, when that is done and there is a raise SomeError statement within the decorated unit tests scope (a function called from the test case will throw a SomeError if some certain test requirements aren't met), and this Error Class is caught in my decorator, then the test is never executed. However if i remove any raise SomeError statements within the testcase, it runs fine.

My decorator:

def try_exceptor(f):
    @functools.wraps(f)
    def inner(self):
        try:
            return f(self)
        except KeyError as k:
            print k
        except MyLocustFailError as mlfe:
            print mlfe.message
            newer_assert(mlfe.load_test, mlfe.response, mlfe.message)
    return inner
1

There are 1 answers

0
PistolPete On

I'm a bit embarrassed but I must confess that there never was an issue as I described in my question. Just realized that due to my bad logging setup, the output partially went to my log file (facepalm) for certain scenarios. And because of a changed parameter in a function signature which I did not handle in the function body, the unittest was never asserted as a failure when it should have been. Fooling me to believe that there was something wrong with my decorator.