From 5f2b4080c41b9da04bcf6cc76f19377c4aeb22b0 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 16 Jul 2022 20:50:26 +0200 Subject: Testing for log levels should test the output, not the logger --- tests/test_command.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/test_command.py b/tests/test_command.py index cc64b8f..cbb7aad 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -173,32 +173,35 @@ class testCommand(unittest.TestCase): def test_logging_regular(self): cmd = MyCommand() - with self.assertLogs() as cm: - self._run_with_argv(cmd, [ + with self.assertLogs(): + stream = self._run_with_argv(cmd, [ "mycommand", "loggingsubcommand", ]) - self.assertEqual(len(cm.output), 1) + log_lines = stream["stderr"].getvalue().strip().split("\n") + self.assertEqual(len(log_lines), 1) def test_logging_verbose(self): cmd = MyCommand() - with self.assertLogs() as cm: - self._run_with_argv(cmd, [ + with self.assertLogs(): + stream = self._run_with_argv(cmd, [ "mycommand", "--verbose", "loggingsubcommand", ]) - self.assertEqual(len(cm.output), 2) + log_lines = stream["stderr"].getvalue().strip().split("\n") + self.assertEqual(len(log_lines), 2) def test_logging_debug(self): cmd = MyCommand() - with self.assertLogs() as cm: - self._run_with_argv(cmd, [ + with self.assertLogs(): + stream = self._run_with_argv(cmd, [ "mycommand", "--debug", "loggingsubcommand", ]) - self.assertEqual(len(cm.output), 3) + log_lines = stream["stderr"].getvalue().strip().split("\n") + self.assertEqual(len(log_lines), 3) if __name__ == '__main__': -- cgit v1.2.3