@@ -450,7 +450,8 @@ def test_coverage_startup_producer(self, mock_process_startup):
450450
451451 def test_consumer_argument_parser_setup (self ):
452452 """Test that the consumer argument parser is properly configured"""
453- parser_actions = [action .dest for action in consumer .parser ._actions ]
453+ parser = consumer .build_parser ()
454+ parser_actions = [action .dest for action in parser ._actions ]
454455
455456 assert 'event_type' in parser_actions
456457 assert 'group_id' in parser_actions
@@ -480,8 +481,9 @@ class TestArgumentParsingIntegration:
480481
481482 def test_consumer_with_all_arguments (self ):
482483 """Test consumer argument parsing with all options"""
483- from consumer import parser
484+ from consumer import build_parser
484485
486+ parser = build_parser ()
485487 args = parser .parse_args ([
486488 '--event-type' , 'test_event' ,
487489 '--group-id' , 'test_group' ,
@@ -494,8 +496,9 @@ def test_consumer_with_all_arguments(self):
494496
495497 def test_consumer_with_no_arguments (self ):
496498 """Test consumer argument parsing with no arguments"""
497- from consumer import parser
499+ from consumer import build_parser
498500
501+ parser = build_parser ()
499502 args = parser .parse_args ([])
500503
501504 assert args .event_type is None
@@ -529,11 +532,12 @@ def test_main_function_execution(self, mock_consume_events):
529532 @patch .dict (os .environ , {'KAFKA_TOPIC' : 'custom-topic' , 'KAFKA_BOOTSTRAP_SERVERS' : 'custom:9092' })
530533 def test_main_function_with_arguments_and_custom_env (self , mock_consume_events ):
531534 """Test main function execution with custom environment variables and arguments"""
532- # Mock the args object directly instead of reloading
533- with patch ('consumer.args' ) as mock_args :
534- mock_args .group_id = 'test-group'
535- mock_args .event_type = 'test-event'
536- mock_args .test_mode = False
535+ # Mock the parser to control parsed args
536+ with patch ('consumer.build_parser' ) as mock_build_parser :
537+ from types import SimpleNamespace
538+ mock_parser = Mock ()
539+ mock_parser .parse_args .return_value = SimpleNamespace (group_id = 'test-group' , event_type = 'test-event' , test_mode = False )
540+ mock_build_parser .return_value = mock_parser
537541
538542 consumer .main ()
539543
@@ -550,11 +554,12 @@ def test_main_function_with_arguments_and_custom_env(self, mock_consume_events):
550554 @patch ('consumer.consume_events' )
551555 def test_main_function_with_test_mode (self , mock_consume_events ):
552556 """Test main function execution with test mode argument"""
553- # Mock the args object to simulate test mode
554- with patch ('consumer.args' ) as mock_args :
555- mock_args .group_id = None
556- mock_args .event_type = None
557- mock_args .test_mode = True
557+ # Mock the parser to simulate test mode via parsed args
558+ with patch ('consumer.build_parser' ) as mock_build_parser :
559+ from types import SimpleNamespace
560+ mock_parser = Mock ()
561+ mock_parser .parse_args .return_value = SimpleNamespace (group_id = None , event_type = None , test_mode = True )
562+ mock_build_parser .return_value = mock_parser
558563
559564 consumer .main ()
560565
0 commit comments