Esempio n. 1
0
def test_pytest_configure_misssing_major_rp_options(mocked_config):
    """Test plugin configuration in case of missing required input options.

    The value of the _reportportal_configured attribute of the pytest Config
    object should be changed to False, stopping plugin configuration, if any of
    the following options were not set: rp_endpoint, rp_project, rp_uuid.
    :param mocked_config: Pytest fixture
    """
    mocked_config.getoption.side_effect = (False, False)
    mocked_config.option = mock.Mock()
    mocked_config.option.rp_enabled = True
    mocked_config.getini.return_value = 0
    pytest_configure(mocked_config)
    assert mocked_config._reportportal_configured is False
Esempio n. 2
0
def test_pytest_configure(mocked_config):
    """Test plugin successful configuration.

    :param mocked_get:    Instance of the MagicMock
    :param mocked_config: Pytest fixture
    """
    mocked_config.getoption.side_effect = (False, False)
    mocked_config.option = mock.Mock()
    mocked_config.option.rp_enabled = True
    mocked_config.option.rp_project = None
    pytest_configure(mocked_config)
    expect(mocked_config._reportportal_configured is True)
    expect(
        lambda: isinstance(mocked_config.py_test_service, PyTestServiceClass))
    expect(lambda: isinstance(mocked_config._reporter, RPReportListener))
    assert_expectations()
def test_pytest_configure(mocked_config):
    """Test plugin successful configuration.

    :param mocked_config: Pytest fixture
    """
    mocked_config.option.rp_enabled = True
    mocked_config.option.rp_project = None
    pytest_configure(mocked_config)
    expect(mocked_config._rp_enabled is True)
    expect(
        lambda: isinstance(mocked_config.py_test_service, PyTestServiceClass))
    assert_expectations()
    mocked_config.getoption.assert_has_calls([
        mock.call('--collect-only', default=False),
        mock.call('--setup-plan', default=False)
    ])
def test_pytest_configure_on_conn_error(mocked_get, mocked_config):
    """Test plugin configuration in case of HTTP error.

    The value of the _reportportal_configured attribute of the pytest Config
    object should be changed to False, stopping plugin configuration, if HTTP
    error occurs getting HTTP response from the ReportPortal.
    :param mocked_get:    Instance of the MagicMock
    :param mocked_config: Pytest fixture
    """
    mock_response = mock.Mock()
    mock_response.raise_for_status.side_effect = RequestException()
    mocked_get.return_value = mock_response
    mocked_config.option.rp_enabled = True
    mocked_config.option.rp_skip_connection_test = 'False'
    pytest_configure(mocked_config)
    assert mocked_config._rp_enabled is False
def test_pytest_configure_misssing_rp_uuid(mocked_log, mocked_config):
    """Test plugin configuration in case of missing rp_uuid.

    The value of the _reportportal_configured attribute of the pytest Config
    object should be changed to False, stopping plugin configuration, if
    rp_uuid is not set.

    :param mocked_config: Pytest fixture
    """
    mocked_config.option.rp_enabled = True
    mocked_config.option.rp_uuid = None
    mocked_config.getini.return_value = 0
    pytest_configure(mocked_config)
    assert mocked_config._rp_enabled is False
    mocked_log.debug.assert_has_calls([
        mock.call(
            MANDATORY_PARAMETER_MISSED_PATTERN.format(
                mocked_config.option.rp_project,
                mocked_config.option.rp_endpoint,
                None,
            )),
        mock.call('Disabling reporting to RP.'),
    ])
Esempio n. 6
0
def test_stop_plugin_configuration_on_conn_error(mocked_get, mocked_config):
    """Test plugin configuration in case of HTTP error.

    The value of the _reportportal_configured attribute of the pytest Config
    object should be changed to False, stopping plugin configuration, if HTTP
    error occurs getting HTTP response from the ReportPortal.
    :param mocked_get:    Instance of the MagicMock
    :param mocked_config: Pytest fixture
    """
    mock_response = mock.Mock()
    mock_response.raise_for_status.side_effect = RequestException()
    mocked_get.return_value = mock_response
    expect(pytest_configure(mocked_config) is None,
           'Received unexpected return value from pytest_configure.')
    expect(mocked_config._reportportal_configured is False,
           'The value of the _reportportal_configured is not False.')
    assert_expectations()
Esempio n. 7
0
def test_pytest_configure_dry_run(mocked_config):
    """Test plugin configuration in case of dry-run execution."""
    mocked_config.getoption.return_value = True
    pytest_configure(mocked_config)
    assert mocked_config._reportportal_configured is False