itamarst / eliot

Eliot: the logging system that tells you *why* it happened
https://eliot.readthedocs.io
Apache License 2.0
1.11k stars 66 forks source link

Add an API that can be called directly at the end of a test (eg in tearDown) to validate logging #364

Closed exarkun closed 5 years ago

exarkun commented 5 years ago

I would like to apply generic serialization validation to all tests in a particular TestCase. I could decorate every test with @capture_logging(None). It would be easier if I could instead just call some Eliot API in my tearDown (or as a cleanup function with addCleanup). Perhaps this would need to be paired with some setUp API (I don't know). That would be fine. It still means two changes to my test suite instead of N.

exarkun commented 5 years ago

For example, perhaps:

class FooTests(TestCase):
    def setUp(self):
        validator = eliot.testing.get_ready_for_validation()
        self.addCleanup(validator.validate_it_now)
exarkun commented 5 years ago

I suppose a class decorator could be another approach.

@eliot.testing.capture_logging_for_all_tests(None)
class FooTests(TestCase):
    ...
exarkun commented 5 years ago

Having an API I can call at any point I want would also make this kind of testing more Twisted-friendly, I think. As far as I can tell, test methods that return a Deferred don't interact nicely with @capture_logging.

itamarst commented 5 years ago

OK, makes sense.