Skip to content

Commit

Permalink
Change: Suppress console output while testing error cases
Browse files Browse the repository at this point in the history
Redirect stderror when testing errors to silence the tests.
  • Loading branch information
bjoernricks committed Apr 5, 2023
1 parent a2205b8 commit 2193e9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions tests/version/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def test_verify_current(self):
self.assertEqual(cm.exception.code, VersionExitCode.SUCCESS)

def test_next_invalid_current(self):
with temp_directory(change_into=True) as temp_dir, self.assertRaises(
SystemExit
) as cm:
with redirect_stderr(StringIO()), temp_directory(
change_into=True
) as temp_dir, self.assertRaises(SystemExit) as cm:
version_file = temp_dir / "package.json"
version_file.write_text(
'{"name": "foo", "version": "1.2.tt"}',
Expand Down
4 changes: 3 additions & 1 deletion tests/version/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import unittest
from contextlib import redirect_stderr
from io import StringIO

from pontos.version.parser import parse_args


class ParserTestCase(unittest.TestCase):
def test_error_while_parsing(self):
with self.assertRaises(SystemExit) as cm:
with redirect_stderr(StringIO()), self.assertRaises(SystemExit) as cm:
parse_args(["update", "foo"])

# exception code in argparse
Expand Down

0 comments on commit 2193e9d

Please sign in to comment.