summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2022-07-16 20:50:26 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2022-07-16 20:50:26 +0200
commit5f2b4080c41b9da04bcf6cc76f19377c4aeb22b0 (patch)
tree7fa740034920e532fe162f8c20fc8fa675da8eb9
parent6b5372ddbb5997f673346d86b9c1efe17fddf099 (diff)
Testing for log levels should test the output, not the logger
-rw-r--r--tests/test_command.py21
1 files changed, 12 insertions, 9 deletions
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__':