This SO question is a bit dated, but there's also a pubsub emulator[1] that you might find useful.
[1] https://stackoverflow.com/questions/43354599/dataflow-pipeline-and-pubsub-emulator On Tue, Jul 27, 2021 at 1:00 PM Ning Kang <ni...@google.com> wrote: > In the example test, the `mock_pubsub` is from `patch`: > @mock.patch('google.cloud.pubsub.SubscriberClient') for `class > TestReadFromPubSub(unittest.TestCase)`, then in the test functions, the > second arguments are the patched `google.cloud.pubsub.SubscriberClient`. > For example, "def test_read_messages_success(self, mock_pubsub)". > See the usage of patch decorator here > <https://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch> > . > > > You can also use TestStream to simulate a streaming source: > https://github.com/apache/beam/blob/master/sdks/python/apache_beam/testing/test_stream_test.py > > On Mon, Jul 26, 2021 at 11:21 PM Bergmeier, Andreas < > andreas.bergme...@otto.de> wrote: > >> We have a PTransform, which uses ReadFromPubSub and now would like to >> test it. >> Looking at >> https://github.com/apache/beam/blob/master/sdks/python/apache_beam/io/gcp/pubsub_test.py >> it seems like we would need something similar to TestReadFromPubSub. >> I do however not understand how this works at all since e.g. there seems >> to appear a mock_pubsub out of thin air. >> Can someone please give a rough sketch which parts need to work together >> how in order to test ReadFromPubSub in a TestPipeline? >> >