1515import sys
1616import warnings
1717from io import StringIO
18+ from unittest import mock
1819
1920from delayed_assert import expect , assert_expectations
20- from unittest import mock
2121
22+ from reportportal_client import OutputType
2223from examples .test_rp_logging import LOG_MESSAGE
23- from pytest_reportportal .config import OUTPUT_TYPES
2424from tests import REPORT_PORTAL_SERVICE
2525from tests .helpers import utils
2626
@@ -285,20 +285,11 @@ def test_launch_uuid_print(mock_client_init):
285285 print_uuid = True
286286 variables = utils .DEFAULT_VARIABLES .copy ()
287287 variables .update ({'rp_launch_uuid_print' : str (print_uuid )}.items ())
288-
289- str_io = StringIO ()
290- stdout = sys .stdout
291- try :
292- OUTPUT_TYPES ['stdout' ] = str_io
293- result = utils .run_pytest_tests (['examples/test_rp_logging.py' ],
294- variables = variables )
295- finally :
296- OUTPUT_TYPES ['stdout' ] = stdout
297-
288+ result = utils .run_pytest_tests (['examples/test_rp_logging.py' ], variables = variables )
298289 assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
299290 expect (mock_client_init .call_count == 1 )
300291 expect (mock_client_init .call_args_list [0 ][1 ]['launch_uuid_print' ] == print_uuid )
301- expect (mock_client_init .call_args_list [0 ][1 ]['print_output' ] is str_io )
292+ expect (mock_client_init .call_args_list [0 ][1 ]['print_output' ] is None )
302293 assert_expectations ()
303294
304295
@@ -307,20 +298,11 @@ def test_launch_uuid_print_stderr(mock_client_init):
307298 print_uuid = True
308299 variables = utils .DEFAULT_VARIABLES .copy ()
309300 variables .update ({'rp_launch_uuid_print' : str (print_uuid ), 'rp_launch_uuid_print_output' : 'stderr' }.items ())
310-
311- str_io = StringIO ()
312- stderr = sys .stderr
313- try :
314- OUTPUT_TYPES ['stderr' ] = str_io
315- result = utils .run_pytest_tests (['examples/test_rp_logging.py' ],
316- variables = variables )
317- finally :
318- OUTPUT_TYPES ['stderr' ] = stderr
319-
301+ result = utils .run_pytest_tests (['examples/test_rp_logging.py' ], variables = variables )
320302 assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
321303 expect (mock_client_init .call_count == 1 )
322304 expect (mock_client_init .call_args_list [0 ][1 ]['launch_uuid_print' ] == print_uuid )
323- expect (mock_client_init .call_args_list [0 ][1 ]['print_output' ] is str_io )
305+ expect (mock_client_init .call_args_list [0 ][1 ]['print_output' ] is OutputType . STDERR )
324306 assert_expectations ()
325307
326308
@@ -329,38 +311,17 @@ def test_launch_uuid_print_invalid_output(mock_client_init):
329311 print_uuid = True
330312 variables = utils .DEFAULT_VARIABLES .copy ()
331313 variables .update ({'rp_launch_uuid_print' : str (print_uuid ), 'rp_launch_uuid_print_output' : 'something' }.items ())
332-
333- str_io = StringIO ()
334- stdout = sys .stdout
335- try :
336- OUTPUT_TYPES ['stdout' ] = str_io
337- result = utils .run_pytest_tests (['examples/test_rp_logging.py' ],
338- variables = variables )
339- finally :
340- OUTPUT_TYPES ['stdout' ] = stdout
341-
342- assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
343- expect (mock_client_init .call_count == 1 )
344- expect (mock_client_init .call_args_list [0 ][1 ]['launch_uuid_print' ] == print_uuid )
345- expect (mock_client_init .call_args_list [0 ][1 ]['print_output' ] is str_io )
346- assert_expectations ()
314+ result = utils .run_pytest_tests (['examples/test_rp_logging.py' ], variables = variables )
315+ assert int (result ) == 3 , 'Exit code should be 3 (INTERNALERROR)'
316+ assert mock_client_init .call_count == 0
347317
348318
349319@mock .patch (REPORT_PORTAL_SERVICE )
350320def test_no_launch_uuid_print (mock_client_init ):
351321 variables = utils .DEFAULT_VARIABLES .copy ()
352-
353- str_io = StringIO ()
354- stdout = sys .stdout
355- try :
356- OUTPUT_TYPES ['stdout' ] = str_io
357- result = utils .run_pytest_tests (['examples/test_rp_logging.py' ],
358- variables = variables )
359- finally :
360- OUTPUT_TYPES ['stdout' ] = stdout
361-
322+ result = utils .run_pytest_tests (['examples/test_rp_logging.py' ], variables = variables )
362323 assert int (result ) == 0 , 'Exit code should be 0 (no errors)'
363324 expect (mock_client_init .call_count == 1 )
364325 expect (mock_client_init .call_args_list [0 ][1 ]['launch_uuid_print' ] is False )
365- expect (mock_client_init .call_args_list [0 ][1 ]['print_output' ] is str_io )
326+ expect (mock_client_init .call_args_list [0 ][1 ]['print_output' ] is None )
366327 assert_expectations ()
0 commit comments