diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 584462b741ee99..435db65d52fddb 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -5811,9 +5811,8 @@ def test_invalid_args(self): parser = ErrorRaisingArgumentParser(prog='PROG') parser.add_argument('--foo', nargs="*") parser.add_argument('foo') - with captured_stderr() as stderr: + with self.assertWarns(UserWarning): parser.parse_intermixed_args(['hello', '--foo']) - self.assertIn("UserWarning", stderr.getvalue()) class TestIntermixedMessageContentError(TestCase): # case where Intermixed gives different error message