-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Pub/Sub: update how to test with mock #2555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
1a85239
1abf3c9
666b6bd
0cccbf8
96c66fe
3acf66a
5eba4fa
83bbf39
475a57d
6617f22
bca6eef
a3b9de3
06d0ce6
3242686
8670eff
ffa76bb
e877d54
6fb596c
85a3d98
9ef38f5
a4d9a26
b4a0120
4fadbfc
fffd0fd
7cf5693
d2afe6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| import os | ||
| import time | ||
| import uuid | ||
|
|
||
| from gcp_devrel.testing import eventually_consistent | ||
| from google.cloud import pubsub_v1 | ||
|
|
@@ -22,8 +23,9 @@ | |
|
|
||
| import publisher | ||
|
|
||
| UUID = uuid.uuid4().hex | ||
| PROJECT = os.environ['GCLOUD_PROJECT'] | ||
| TOPIC = 'publisher-test-topic' | ||
| TOPIC = 'publisher-test-topic-' + UUID | ||
|
|
||
|
|
||
| @pytest.fixture | ||
|
|
@@ -56,6 +58,12 @@ def new_sleep(period): | |
| return mock.patch('time.sleep', new=new_sleep) | ||
|
|
||
|
|
||
| def _to_delete(): | ||
| publisher_client = pubsub_v1.PublisherClient() | ||
| publisher_client.delete_topic('projects/{}/topics/{}'.format( | ||
| PROJECT, TOPIC)) | ||
|
|
||
|
|
||
| def test_list(client, topic, capsys): | ||
| @eventually_consistent.call | ||
| def _(): | ||
|
|
@@ -127,3 +135,5 @@ def test_publish_with_futures(topic, capsys): | |
|
|
||
| out, _ = capsys.readouterr() | ||
| assert 'Published' in out | ||
|
|
||
| _to_delete() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can these https://docs.pytest.org/en/latest/fixture.html#fixture-finalization-executing-teardown-code
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to call delete out in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can address this in a different PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me |
||
Uh oh!
There was an error while loading. Please reload this page.