Skip to content

Commit

Permalink
YDA-5512: Add mock stderr in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
claravox committed Jan 17, 2024
1 parent c43b75f commit 3747df3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions unit-tests/test_importgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import sys
from unittest import TestCase
from unittest.mock import patch
from io import StringIO

sys.path.append("../yclienttools")

Expand Down Expand Up @@ -96,7 +98,7 @@ def test_missing_fields_1_9(self):
self.assertTupleEqual(expected, result)
self.assertIsNone(error_msg)

# Missing subcategory
# Missing subcategory (should give error)
d = {
"category": ["test-automation"],
"groupname": ["groupteama2"],
Expand All @@ -111,7 +113,8 @@ def test_missing_fields_1_9(self):

def test_error_fields_1_8(self):
args = {"offline_check": True}
# Includes (valid) schema id and expiration, even though those are not in version 1.8
# Includes (valid) schema id and expiration,
# which are not in version 1.8 (should give error)
d = {
"category": ["test-automation"],
"subcategory": ["initial"],
Expand All @@ -126,7 +129,8 @@ def test_error_fields_1_8(self):
self.assertIsNone(result)
self.assertIn("1.9", error_msg)

def test_parse_invalid_csv_file(self):
@patch('sys.stderr', new_callable=StringIO)
def test_parse_invalid_csv_file(self, mock_stderr):
# csv that has an unlabeled header
args = {"offline_check": True}
with self.assertRaises(SystemExit):
Expand Down

0 comments on commit 3747df3

Please sign in to comment.