11"""This modules includes unit tests for the plugin."""
22
3- from requests .exceptions import RequestException
43try :
54 from unittest .mock import create_autospec , Mock , patch
65except ImportError :
76 from mock import create_autospec , Mock , patch
87
98from _pytest .config import Config
109from delayed_assert import expect , assert_expectations
10+ import pytest
11+ from requests .exceptions import RequestException
1112
1213from pytest_reportportal .plugin import pytest_configure
14+ from pytest_reportportal import RPLogger
15+
16+
17+ @pytest .fixture
18+ def logger ():
19+ return RPLogger ("pytest_reportportal.test" )
1320
1421
1522@patch ('pytest_reportportal.plugin.requests.get' )
@@ -31,3 +38,28 @@ def test_stop_plugin_configuration_on_conn_error(mocked_get):
3138 expect (mocked_config ._reportportal_configured is False ,
3239 'The value of the _reportportal_configured is not False.' )
3340 assert_expectations ()
41+
42+
43+ @patch ('pytest_reportportal.RPLogger.handle' )
44+ @pytest .mark .parametrize ("log_level" , ("info" , "debug" , "warning" , "error" ))
45+ def test_logger_handle_attachment (mock_handler , logger , log_level ):
46+ """Test logger call for different log levels with some text attachment."""
47+ log_call = getattr (logger , log_level )
48+ attachment = "Some {} attachment" .format (log_level )
49+ log_call ("Some {} message" .format (log_level ), attachment = attachment )
50+ expect (mock_handler .call_count == 1 , "logger.handle called more than 1 time" )
51+ expect (getattr (mock_handler .call_args [0 ][0 ], "attachment" ) == attachment ,
52+ "record.attachment in args doesn't match real value" )
53+ assert_expectations ()
54+
55+
56+ @patch ('pytest_reportportal.RPLogger.handle' )
57+ @pytest .mark .parametrize ("log_level" , ("info" , "debug" , "warning" , "error" ))
58+ def test_logger_handle_no_attachment (mock_handler , logger , log_level ):
59+ """Test logger call for different log levels without any attachment."""
60+ log_call = getattr (logger , log_level )
61+ log_call ("Some {} message" .format (log_level ))
62+ expect (mock_handler .call_count == 1 , "logger.handle called more than 1 time" )
63+ expect (getattr (mock_handler .call_args [0 ][0 ], "attachment" ) is None ,
64+ "record.attachment in args is not None" )
65+ assert_expectations ()
0 commit comments