8000 Convert tasks example to use logging for testability (#1219) · johnmanong/python-docs-samples@19788b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 19788b0

Browse files
authored
Convert tasks example to use logging for testability (GoogleCloudPlatform#1219)
* Convert tasks example to use logging for testability * Use capsys to test tasks
1 parent 6f0f4f9 commit 19788b0

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

appengine/flexible/tasks/main_test.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import mock
1615
import pytest
1716

1817

@@ -28,19 +27,19 @@ def test_index(app):
2827
assert r.status_code == 200
2928

3029

31-
@mock.patch('logging.warn')
32-
def test_log_payload(logging_mock, app):
33-
payload = 'hello'
30+
def test_log_payload(capsys, app):
31+
payload = 'test_payload'
3432

3533
r = app.post('/log_payload', data=payload)
3634
assert r.status_code == 200
3735

38-
assert logging_mock.called
36+
out, _ = capsys.readouterr()
37+
assert payload in out
3938

4039

41-
@mock.patch('logging.warn')
42-
def test_empty_payload(logging_mock, app):
40+
def test_empty_payload(capsys, app):
4341
r = app.post('/log_payload')
4442
assert r.status_code == 200
4543

46-
assert logging_mock.called
44+
out, _ = capsys.readouterr()
45+
assert 'empty payload' in out

0 commit comments

Comments
 (0)
0