(self)
| 62 | parser.exit(status=0, message='foo') |
| 63 | |
| 64 | def test_skip_invalid_stdout(self): |
| 65 | parser = argparse.ArgumentParser() |
| 66 | for func in ( |
| 67 | parser.print_usage, |
| 68 | parser.print_help, |
| 69 | functools.partial(parser.parse_args, ['-h']) |
| 70 | ): |
| 71 | with ( |
| 72 | self.subTest(func=func), |
| 73 | contextlib.redirect_stdout(None), |
| 74 | # argparse uses stderr as a fallback |
| 75 | StdIOBuffer() as mocked_stderr, |
| 76 | contextlib.redirect_stderr(mocked_stderr), |
| 77 | mock.patch('argparse._sys.exit'), |
| 78 | ): |
| 79 | func() |
| 80 | self.assertRegex(mocked_stderr.getvalue(), r'usage:') |
| 81 | |
| 82 | |
| 83 | class TestArgumentParserPickleable(unittest.TestCase): |
nothing calls this directly
no test coverage detected