Skip to content

opentelemetry-instrumentation-aiokafka: test warnings — Unclosed AIOKafkaProducer and unawaited coroutine #4383

@dorlib

Description

@dorlib

Describe your environment

OS: any
Python version: 3.13, 3.14
Package version: opentelemetry-instrumentation-aiokafka 0.62b0.dev

What happened?

Running the aiokafka instrumentation test suite produces two warnings:

  1. ERROR asyncio:base_events.py: Unclosed AIOKafkaProducer intest_send_and_wait. the test creates a producer but never calls producer.stop(), leaving the resource unclosed.

  2. RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited in test_wrap_getmany. the _create_consumer_span parameter is typed as mock.MagicMock but the real function is async. When the code calls await _create_consumer_span(...) and then record_span.get_span_context(), the MagicMock auto-creates coroutine return values that are never awaited.

Steps to Reproduce

tox -e py3-test-instrumentation-aiokafka -- -v

Observe the Unclosed AIOKafkaProducer error log during test_send_and_wait
and the RuntimeWarning after the test session completes.

Expected Result

Tests run cleanly with no resource warnings or unawaited coroutine warnings.

Actual Result

ERROR    asyncio:base_events.py:1871 Unclosed AIOKafkaProducer
producer: <aiokafka.producer.producer.AIOKafkaProducer object at 0x...>
RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited

Additional context

Neither warning causes test failures — all 17 tests pass. These are cosmetic
issues but they add noise to the test output and could mask real warnings.

Would you like to implement a fix?

Yes, PR opened #4384

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions