5050TEST_ACTION_PATH = os .path .join (tests_base .get_resources_path (), 'packs' ,
5151 'pythonactions/actions/test.py' )
5252PATHS_ACTION_PATH = os .path .join (tests_base .get_resources_path (), 'packs' ,
53- 'pythonactions/actions/python_paths.py' )
53+ 'pythonactions/actions/python_paths.py' )
5454ACTION_1_PATH = os .path .join (tests_base .get_fixtures_path (),
5555 'packs/dummy_pack_9/actions/list_repos_doesnt_exist.py' )
5656ACTION_2_PATH = os .path .join (tests_base .get_fixtures_path (),
6565PRINT_CONFIG_ITEM_ACTION = os .path .join (tests_base .get_resources_path (), 'packs' ,
6666 'pythonactions/actions/print_config_item_doesnt_exist.py' )
6767PRINT_TO_STDOUT_STDERR_ACTION = os .path .join (tests_base .get_resources_path (), 'packs' ,
68- 'pythonactions/actions/print_to_stdout_and_stderr.py' )
68+ 'pythonactions/actions/print_to_stdout_and_stderr.py' )
6969
7070
7171# Note: runner inherits parent args which doesn't work with tests since test pass additional
@@ -315,8 +315,8 @@ def test_action_stdout_and_stderr_is_not_stored_in_db_by_default(self, mock_spaw
315315 runner .pre_run ()
316316 (_ , output , _ ) = runner .run ({'row_index' : 4 })
317317
318- self .assertEqual (output ['stdout' ], 'pre result line 1\n post result line 1' )
319- self .assertEqual (output ['stderr' ], 'stderr line 1\n stderr line 2\n stderr line 3\n ' )
318+ self .assertMultiLineEqual (output ['stdout' ], 'pre result line 1\n post result line 1' )
319+ self .assertMultiLineEqual (output ['stderr' ], 'stderr line 1\n stderr line 2\n stderr line 3\n ' )
320320 self .assertEqual (output ['result' ], 'True' )
321321 self .assertEqual (output ['exit_code' ], 0 )
322322
@@ -339,8 +339,8 @@ def test_action_stdout_and_stderr_is_not_stored_in_db_by_default(self, mock_spaw
339339 runner .pre_run ()
340340 (_ , output , _ ) = runner .run ({'row_index' : 4 })
341341
342- self .assertEqual (output ['stdout' ], 'pre result line 1\n post result line 1' )
343- self .assertEqual (output ['stderr' ], 'stderr line 1\n stderr line 2\n stderr line 3\n ' )
342+ self .assertMultiLineEqual (output ['stdout' ], 'pre result line 1\n post result line 1' )
343+ self .assertMultiLineEqual (output ['stderr' ], 'stderr line 1\n stderr line 2\n stderr line 3\n ' )
344344 self .assertEqual (output ['result' ], 'True' )
345345 self .assertEqual (output ['exit_code' ], 0 )
346346
@@ -387,9 +387,9 @@ def test_action_stdout_and_stderr_is_stored_in_the_db(self, mock_spawn, mock_pop
387387 runner .pre_run ()
388388 (_ , output , _ ) = runner .run ({'row_index' : 4 })
389389
390- self .assertEqual (output ['stdout' ],
390+ self .assertMultiLineEqual (output ['stdout' ],
391391 'pre result line 1\n pre result line 2\n post result line 1' )
392- self .assertEqual (output ['stderr' ], 'stderr line 1\n stderr line 2\n stderr line 3\n ' )
392+ self .assertMultiLineEqual (output ['stderr' ], 'stderr line 1\n stderr line 2\n stderr line 3\n ' )
393393 self .assertEqual (output ['result' ], 'True' )
394394 self .assertEqual (output ['exit_code' ], 0 )
395395
@@ -420,19 +420,26 @@ def test_real_time_output_streaming_bufsize(self):
420420 group = 'actionrunner' )
421421
422422 output_dbs = ActionExecutionOutput .get_all ()
423- self .assertEqual (len (output_dbs ), (index - 1 ) * 4 )
423+ # Unexpected third party warnings will also inflate this number
424+ self .assertGreaterEqual (len (output_dbs ), (index - 1 ) * 4 )
424425
425426 runner = self ._get_mock_runner_obj ()
426427 runner .entry_point = PRINT_TO_STDOUT_STDERR_ACTION
427428 runner .pre_run ()
428429 (_ , output , _ ) = runner .run ({'stdout_count' : 2 , 'stderr_count' : 2 })
429430
430- self .assertEqual (output ['stdout' ], 'stdout line 0\n stdout line 1\n ' )
431- self .assertEqual (output ['stderr' ], 'stderr line 0\n stderr line 1\n ' )
431+ # assertMultiLineEqual displays a diff if the two don't match
432+ self .assertMultiLineEqual (output ['stdout' ], 'stdout line 0\n stdout line 1\n ' )
433+ # Third party packages can unexpectedly emit warnings and add more
434+ # output to the streamed stderr, so we check that the expected
435+ # lines occurred, but we allow additional lines to exist
436+ self .assertIn ('stderr line 0\n ' , output ['stderr' ])
437+ self .assertIn ('stderr line 1\n ' , output ['stderr' ])
432438 self .assertEqual (output ['exit_code' ], 0 )
433439
434440 output_dbs = ActionExecutionOutput .get_all ()
435- self .assertEqual (len (output_dbs ), (index ) * 4 )
441+ # Unexpected third party warnings will also inflate this number
442+ self .assertGreaterEqual (len (output_dbs ), (index ) * 4 )
436443
437444 @mock .patch ('st2common.util.concurrency.subprocess_popen' )
438445 def test_stdout_interception_and_parsing (self , mock_popen ):
@@ -701,7 +708,9 @@ def test_simple_action_log_messages_and_log_level_runner_param(self):
701708 lines .append (line )
702709
703710 msg = ('Expected %s lines, got %s - "%s"' % (expected_count , len (lines ), str (lines )))
704- self .assertEqual (len (lines ), expected_count , msg )
711+ # Dependencies can inject their own warnings, which increases the
712+ # number of lines to more than we expect with simple equality checks
713+ self .assertGreaterEqual (len (lines ), expected_count , msg )
705714
706715 # Only log messages with level info and above should be displayed
707716 runner = self ._get_mock_runner_obj ()
0 commit comments