From 5b3a827a1ff80e4b51c7ede44b84bf640d5b6380 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 18 Sep 2019 11:58:12 -0400 Subject: Provide stderr in exception when check_parser fails For negative tests that are asserting an argparse failure it would be useful to assert the specific reason for the failure in the test rather than just getting an exception, especially to avoid false positives in the tests when what is being tested and failing isn't the actual expected reason for the failure. This wraps the check_parser code that parses the args and mocks sys.stderr so we can trap that output and put it in the exception message that gets raised to the test. As a result, we can tighten up a test that was passing before for the wrong reason [1]. [1] https://review.opendev.org/#/c/673725/12/openstackclient/tests/unit/compute/v2/test_server.py@605 Change-Id: I0f1dc1215bdfb3eba98ccaf66a0041d220b93812 --- openstackclient/tests/unit/compute/v2/test_server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'openstackclient/tests/unit/compute/v2/test_server.py') diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index c70d6d72..c2bac277 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -626,7 +626,8 @@ class TestServerVolumeV279(TestServerVolume): ex = self.assertRaises(utils.ParserException, self.check_parser, self.cmd, arglist, verifylist) - self.assertIn('Argument parse failed', str(ex)) + self.assertIn('argument --disable-delete-on-termination: not allowed ' + 'with argument --enable-delete-on-termination', str(ex)) class TestServerAddNetwork(TestServer): -- cgit v1.2.1