diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 753a8dad7195ae..eb744468b55602 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -5874,9 +5874,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