Exemple #1
0
    def test_raises_immediately_if_exception_and_no_timeout_set(
        self, mocker, time_mock
    ):
        method = mocker.Mock(side_effect=NormalTestError)

        with pytest.raises(NormalTestError):
            retry_with_timeout(method, 0)

        method.assert_called_once()
Exemple #2
0
    def test_emits_single_warning_if_file_not_found(self, mocker, time_mock):
        method = mocker.Mock(side_effect=FileNotFoundError("error message"))

        with pytest.raises(FileNotFoundError):
            with pytest.warns(UserWarning) as record:
                retry_with_timeout(method, 30)

        warning_messages = [r.message.args[0] for r in record]
        assert_that(warning_messages, is_(["error message"]))
Exemple #3
0
    def test_does_not_log_progress_by_default(self, mocker, time_mock, capsys):
        def side_effect():
            if time_mock.time < 4:
                raise NormalTestError
            return 42

        method = mocker.Mock(side_effect=side_effect)

        retry_with_timeout(method, 30)

        assert_that(capsys.readouterr().out, is_(""))
Exemple #4
0
    def test_raises_if_abort_is_raised(self, mocker, time_mock):
        def side_effect():
            if time_mock.time < 10:
                raise NormalTestError
            elif time_mock.time < 11:
                raise RetryAbort(AbortedTestError())
            return 42

        method = mocker.Mock(side_effect=side_effect)

        with pytest.raises(AbortedTestError):
            retry_with_timeout(method, 30)
Exemple #5
0
    def test_logs_progress_if_logging_enabled(self, mocker, time_mock, capsys):
        def side_effect():
            if time_mock.time < 4:
                raise NormalTestError
            return 42

        method = mocker.Mock(side_effect=side_effect)

        retry_with_timeout(method, 30, log=True)

        assert_that(
            capsys.readouterr().out, is_("0...\b\b\b\b1...\b\b\b\b2...\b\b\b\b3...")
        )
Exemple #6
0
    def test_returns_if_no_exception_just_before_timeout(self, mocker, time_mock):
        def side_effect():
            if time_mock.time < 30:
                raise NormalTestError
            return 42

        method = mocker.Mock(side_effect=side_effect)

        result = retry_with_timeout(method, 30)

        assert_that(result, is_(42))
Exemple #7
0
    def test_raises_if_exception_after_timeout(self, mocker, time_mock):
        method = mocker.Mock(side_effect=NormalTestError)

        with pytest.raises(NormalTestError):
            retry_with_timeout(method, 30)
Exemple #8
0
    def test_returns_if_no_exception(self, mocker):
        method = mocker.Mock(return_value=42)

        result = retry_with_timeout(method, 30)

        assert_that(result, is_(42))