From 2ea0bcd42aaa24b0fba1cda47e1d37b65e6fdad8 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sat, 3 Dec 2022 10:21:03 -0800 Subject: [PATCH] clean up test output, and verify that the error message is correct.. --- loraserv.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/loraserv.py b/loraserv.py index e60b3b0..3ec990b 100644 --- a/loraserv.py +++ b/loraserv.py @@ -1,5 +1,6 @@ import argparse import asyncio +import io import multicast import sys import unittest @@ -168,10 +169,15 @@ class TestLoraServ(unittest.IsolatedAsyncioTestCase): @timeout(2) async def test_argerrors(self): - # it'd be nice to silence the usage output here - with self.assertRaises(SystemExit) as cm, \ - patch.dict(sys.__dict__, dict(argv=[ 'name', ])): - await main() + with io.StringIO() as fp: + with self.assertRaises(SystemExit) as cm, \ + patch.dict(sys.__dict__, dict(argv=[ 'name', ], + stderr=fp)): + await main() + + errout = fp.getvalue() + + self.assertEqual(errout, 'usage: name [-h] [-a maddr] serdev\nname: error: the following arguments are required: serdev\n') self.assertEqual(cm.exception.code, 2)