Capture warnings and assert in tests