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)