Code review comment for lp://staging/~vila/ols-store-tests/ols-run-tests

Revision history for this message
Vincent Ladeuil (vila) wrote :

> What if we made this part of the setUp and tearDown process and put it in the base TestCase.

The thing is, this trick requires wrapping the test method itself.

There is no good way (at least I haven't found any so far) that can be achieved "transparently" for all test methods.

If you look at the unittest implementation, you'll see that __call__() calls run() which provides no way to wrap the test method call (search for testMethod there) itself.

Alternatively, this may be be implemented on the TestResult object but that looks brittle (and would require implementing it for all TestResult objects).

This code originated in ols-vms (https://bazaar.launchpad.net/~ubuntuone-hackers/ols-vms/trunk/view/head:/olsvms/tests/__init__.py#L55 but is not used there anymore) and worked well, the constraint of explicitly decorating each test may seem a bit tedious but was worth it (not all tests have a use for that).

While borrowing it I attempted to do just what you suggest but fail.

Come to think of it that should allow the implementation to be simplified (there is no need for a class since there are no level and fmt parameters anymore).

Also note that here, we're not calling logging from any code under test, we only use it as part of the test code.

So this proposal is to activate it where we need it. As such, it's not exposed either where it's not needed.

I'll keep thinking about generalizing it though.

« Back to merge proposal