Skip to content

Commit 75ebce4

Browse files
author
renzon
committed
Utilizado Pytest Mock
1 parent ae87981 commit 75ebce4

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

libpythonpro/tests/test_spam/test_github_api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77

88
@pytest.fixture
9-
def avatar_url():
9+
def avatar_url(mocker):
1010
resp_mock = Mock()
1111
url = 'https://avatars3.githubusercontent.com/u/402714?v=4'
1212
resp_mock.json.return_value = {
1313
'login': 'renzo', 'id': 402714,
1414
'avatar_url': url,
1515
}
16-
get_original = github_api.requests.get
17-
github_api.requests.get = Mock(return_value=resp_mock)
18-
yield url
19-
github_api.requests.get = get_original
16+
get_mock = mocker.patch('libpythonpro.github_api.requests.get')
17+
get_mock.return_value = resp_mock
18+
return url
2019

2120

2221
def test_buscar_avatar(avatar_url):

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ pytest==3.5.1
1616
coverage==4.5.1
1717
pytest-cov==2.5.1
1818

19+
pytest-mock-1.10.0
20+
1921
-r requirements.txt

0 commit comments

Comments
 (0)