Skip to content

Commit 0633554

Browse files
Suppress errors on close in tests for kafkapython (#1535)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent b4d3c9d commit 0633554

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tests/messagebroker_kafkapython/conftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import json
16+
import logging
1617
import uuid
1718

1819
import kafka
@@ -23,6 +24,8 @@
2324
from newrelic.api.transaction import current_transaction
2425
from newrelic.common.object_wrapper import transient_function_wrapper
2526

27+
_logger = logging.getLogger(__name__)
28+
2629
DB_SETTINGS = kafka_settings()[0]
2730

2831

@@ -81,7 +84,12 @@ def producer(client_type, json_serializer, json_callable_serializer, broker):
8184
)
8285

8386
yield producer
84-
producer.close()
87+
88+
# Close the producer, but ignore any shutdown exceptions
89+
try:
90+
producer.close()
91+
except Exception:
92+
_logger.warning("Exception ignored during Producer.close()", exc_info=True)
8593

8694

8795
@pytest.fixture
@@ -130,7 +138,12 @@ def consumer(group_id, topic, producer, client_type, json_deserializer, json_cal
130138
)
131139

132140
yield consumer
133-
consumer.close()
141+
142+
# Close the consumer, but ignore any shutdown exceptions
143+
try:
144+
consumer.close()
145+
except Exception:
146+
_logger.warning("Exception ignored during Consumer.close()", exc_info=True)
134147

135148

136149
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)