From a5e7a9635eb41cfc0f2aa6135e60f3b13b636c51 Mon Sep 17 00:00:00 2001 From: Sergey Gaynetdinov Date: Mon, 6 Jan 2020 01:00:06 +0500 Subject: [PATCH] Fix raise error StopIteration --- tests/test_fetch.py | 12 ++++++++++++ vk/fetch.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_fetch.py b/tests/test_fetch.py index 711b724..ae22ee4 100644 --- a/tests/test_fetch.py +++ b/tests/test_fetch.py @@ -1,7 +1,10 @@ import io +import pytest + import vk from vk.fetch import Session +from vk.users import User def test_url_open(mocker): @@ -29,3 +32,12 @@ def test_upload_photo(): assert b'Content-Type: application/octet-stream' in data assert b'Python developer and blogger.' in data assert boundary.encode() in data + +def test_fetch_items_stop_iteration(mocker): + fetch = mocker.patch('vk.fetch.Session.fetch') + fetch.return_value = {'items': []} + + got = Session().fetch_items('test', User.from_json, 10) + + with pytest.raises(StopIteration): + next(got) diff --git a/vk/fetch.py b/vk/fetch.py index b0eb38e..761408c 100644 --- a/vk/fetch.py +++ b/vk/fetch.py @@ -65,7 +65,7 @@ def fetch_items(self, method_name, constructor_from_json, count, **params): items = res['items'] if not items: - raise StopIteration + return None for i in items: yield constructor_from_json(self, i)