Message 46934 - Python tracker (original) (raw)
Logged In: YES user_id=80475
After more thought, I think decorators offer a cleaner, more complete solution without further complicating the unittest module.
def rootonly(f): "Decorator to skip tests that require root access" if os.geteuid() == 0: return f return lambda self: 0
@rootonly def testReadingAsRoot(self): . . .
Note the rootonly() decorator need only be defined once instead of writing a full self.skipIf(condition) inside every test. Also, it appears prior to the definition rather than inside. The approach is more flexible than the original proposal though it does lack a reporting mechanism.