From 3c6d128a53d83439036aaec1f1fd48331152935b Mon Sep 17 00:00:00 2001 From: mukund-ananthu <83691193+mukund-ananthu@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:02:36 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20unit=20test=20failures=20in=20https://gi?= =?UTF-8?q?thub.com/googleapis/python-pubsu=E2=80=A6=20(#1074)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytest.ini | 6 ++++-- tests/unit/pubsub_v1/conftest.py | 10 +--------- tests/unit/pubsub_v1/publisher/batch/test_base.py | 9 +-------- tests/unit/pubsub_v1/publisher/batch/test_thread.py | 3 +-- .../publisher/sequencer/test_ordered_sequencer.py | 3 +-- .../publisher/sequencer/test_unordered_sequencer.py | 3 +-- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/pytest.ini b/pytest.ini index e612d31f1..7308b0871 100644 --- a/pytest.ini +++ b/pytest.ini @@ -8,5 +8,7 @@ filterwarnings = ignore:There is no current event loop:DeprecationWarning:grpc.aio._channel # Remove after support for Python 3.7 is dropped ignore:After January 1, 2024, new releases of this library will drop support for Python 3.7:DeprecationWarning - # Remove warning once https://github.com/googleapis/python-pubsub/issues/1067 is fixed - ignore:The return_immediately flag is deprecated and should be set to False.:DeprecationWarning \ No newline at end of file + # Remove warning once https://github.com/googleapis/gapic-generator-python/issues/1938 is fixed + ignore:The return_immediately flag is deprecated and should be set to False.:DeprecationWarning + # Remove warning once https://github.com/googleapis/gapic-generator-python/issues/1939 is fixed + ignore:get_mtls_endpoint_and_cert_source is deprecated.:DeprecationWarning \ No newline at end of file diff --git a/tests/unit/pubsub_v1/conftest.py b/tests/unit/pubsub_v1/conftest.py index e39832d5f..dc4192931 100644 --- a/tests/unit/pubsub_v1/conftest.py +++ b/tests/unit/pubsub_v1/conftest.py @@ -11,16 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import sys import google.auth.credentials - -# special case python < 3.8 -if sys.version_info.major == 3 and sys.version_info.minor < 8: - import mock -else: - from unittest import mock - import pytest @@ -30,4 +22,4 @@ def creds(): Provide test creds to unit tests so that they can run without GOOGLE_APPLICATION_CREDENTIALS set. """ - yield mock.Mock(spec=google.auth.credentials.Credentials) + yield google.auth.credentials.AnonymousCredentials() diff --git a/tests/unit/pubsub_v1/publisher/batch/test_base.py b/tests/unit/pubsub_v1/publisher/batch/test_base.py index c35f482e7..a95d72c12 100644 --- a/tests/unit/pubsub_v1/publisher/batch/test_base.py +++ b/tests/unit/pubsub_v1/publisher/batch/test_base.py @@ -13,13 +13,7 @@ # limitations under the License. from __future__ import absolute_import -import sys -# special case python < 3.8 -if sys.version_info.major == 3 and sys.version_info.minor < 8: - import mock -else: - from unittest import mock from google.auth import credentials from google.cloud.pubsub_v1 import publisher @@ -38,8 +32,7 @@ def create_batch(status, settings=types.BatchSettings()): Returns: ~.pubsub_v1.publisher.batch.thread.Batch: The batch object """ - creds = mock.Mock(spec=credentials.Credentials) - client = publisher.Client(credentials=creds) + client = publisher.Client(credentials=credentials.AnonymousCredentials()) batch = Batch(client, "topic_name", settings) batch._status = status return batch diff --git a/tests/unit/pubsub_v1/publisher/batch/test_thread.py b/tests/unit/pubsub_v1/publisher/batch/test_thread.py index 60658b4ce..2752d62a2 100644 --- a/tests/unit/pubsub_v1/publisher/batch/test_thread.py +++ b/tests/unit/pubsub_v1/publisher/batch/test_thread.py @@ -39,8 +39,7 @@ def create_client(): - creds = mock.Mock(spec=credentials.Credentials) - return publisher.Client(credentials=creds) + return publisher.Client(credentials=credentials.AnonymousCredentials()) def create_batch( diff --git a/tests/unit/pubsub_v1/publisher/sequencer/test_ordered_sequencer.py b/tests/unit/pubsub_v1/publisher/sequencer/test_ordered_sequencer.py index e126c829f..7570c2970 100644 --- a/tests/unit/pubsub_v1/publisher/sequencer/test_ordered_sequencer.py +++ b/tests/unit/pubsub_v1/publisher/sequencer/test_ordered_sequencer.py @@ -36,8 +36,7 @@ def create_message(): def create_client(): - creds = mock.Mock(spec=credentials.Credentials) - return publisher.Client(credentials=creds) + return publisher.Client(credentials=credentials.AnonymousCredentials()) def create_ordered_sequencer(client): diff --git a/tests/unit/pubsub_v1/publisher/sequencer/test_unordered_sequencer.py b/tests/unit/pubsub_v1/publisher/sequencer/test_unordered_sequencer.py index 8a2c486ad..01d9d6ca4 100644 --- a/tests/unit/pubsub_v1/publisher/sequencer/test_unordered_sequencer.py +++ b/tests/unit/pubsub_v1/publisher/sequencer/test_unordered_sequencer.py @@ -34,8 +34,7 @@ def create_message(): def create_client(): - creds = mock.Mock(spec=credentials.Credentials) - return publisher.Client(credentials=creds) + return publisher.Client(credentials=credentials.AnonymousCredentials()) def test_stop():