|
6 | 6 | from mock import create_autospec, Mock, patch |
7 | 7 |
|
8 | 8 | from _pytest.config import Config |
9 | | -from delayed_assert import expect, assert_expectations |
| 9 | +from delayed_assert import expect, assert_expectations |
10 | 10 | import pytest |
11 | 11 | from requests.exceptions import RequestException |
12 | 12 |
|
13 | 13 | from pytest_reportportal.listener import RPReportListener |
14 | | -from pytest_reportportal.plugin import pytest_configure |
| 14 | +from pytest_reportportal.plugin import pytest_configure, pytest_sessionfinish |
15 | 15 | from pytest_reportportal.service import PyTestServiceClass |
16 | 16 | from pytest_reportportal import RPLogger |
17 | 17 |
|
@@ -169,3 +169,27 @@ def iter_markers(name=None): |
169 | 169 | expect(test_item.add_marker.call_args[0][0] == "issue:456823", |
170 | 170 | "item.add_marker called with incorrect parameters") |
171 | 171 | assert_expectations() |
| 172 | + |
| 173 | + |
| 174 | +@patch('pytest_reportportal.plugin.is_master', Mock(return_value=True)) |
| 175 | +@pytest.mark.parametrize('shouldfail, outcome', [ |
| 176 | + (False, False), ('stopping after 1 failures', True) |
| 177 | +]) |
| 178 | +def test_sessionfinish_with_maxfail(shouldfail, outcome): |
| 179 | + """Test session_finish logic when the maxfail Pytest argument is in use. |
| 180 | +
|
| 181 | + :param shouldfail: shouldfail attribute value for the Session object |
| 182 | + :param outcome: nowait argument value passed to the terminate_service() |
| 183 | + """ |
| 184 | + mocked_session = Mock() |
| 185 | + mocked_session.shouldfail = shouldfail |
| 186 | + mocked_session.config = Mock() |
| 187 | + mocked_session.config._reportportal_configured = True |
| 188 | + mocked_session.config.py_test_service.terminate_service = Mock() |
| 189 | + mocked_session.config.py_test_service.finish_launch = Mock() |
| 190 | + pytest_sessionfinish(mocked_session) |
| 191 | + expect(lambda: mocked_session.config.py_test_service. |
| 192 | + finish_launch.assert_called_with(force=outcome, status='RP_Launch')) |
| 193 | + expect(lambda: mocked_session.config.py_test_service. |
| 194 | + terminate_service.assert_called_with(nowait=outcome)) |
| 195 | + assert_expectations() |
0 commit comments