Skip to content

test(mysql): provide concrete DBAPI connection attributes in mocks#4116

Merged
xrmx merged 14 commits intoopen-telemetry:mainfrom
rite7sh:fix-mysql-test-mock-attributes
Feb 20, 2026
Merged

test(mysql): provide concrete DBAPI connection attributes in mocks#4116
xrmx merged 14 commits intoopen-telemetry:mainfrom
rite7sh:fix-mysql-test-mock-attributes

Conversation

@rite7sh
Copy link
Copy Markdown
Contributor

@rite7sh rite7sh commented Jan 21, 2026

Description

This PR updates the MySQL instrumentation integration tests to provide concrete DBAPI connection attributes (host, port, database) in mocked connection and cursor objects.
Previously, several tests emitted OpenTelemetry warnings due to MagicMock values being used for attributes such as db.name, net.peer.name, and net.peer.port. These warnings were noisy but did not cause test failures.
By setting realistic primitive values in the mocks, the tests now run without attribute type warnings, improving signal-to-noise ratio while keeping behavior unchanged.

Fixes #4114

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Ran MySQL instrumentation integration tests locally: tox -e py310-test-instrumentation-mysql-1

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@rite7sh
Copy link
Copy Markdown
Contributor Author

rite7sh commented Jan 21, 2026

This PR only updates tests and does not change runtime behavior or public APIs.
I guess no changelog entry is required. Could a maintainer please add the 'no changelog required' label if you agree?
Thank you :)

@xrmx xrmx moved this to Reviewed PRs that need fixes in Python PR digest Jan 22, 2026
@rite7sh rite7sh requested a review from a team as a code owner January 25, 2026 20:13
@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Please also do a tox -e lint-instrumentation-mysql and commit the changes.

- Introduce make_mysql_commenter_mocks helper
- Remove duplicated MagicMock setup
- Preserve test assertions and behavior
- Improve readability and maintainability
@rite7sh
Copy link
Copy Markdown
Contributor Author

rite7sh commented Feb 18, 2026

@tammy-baylis-swi Thanks for the heads up,I ran tox -e lint-instrumentation-mysql and pushed a follow-up commit with the fixes.
Please have a look whenever you get a chance :)

@tammy-baylis-swi tammy-baylis-swi moved this from Reviewed PRs that need fixes to Ready for review in Python PR digest Feb 19, 2026
Copy link
Copy Markdown
Contributor

@tammy-baylis-swi tammy-baylis-swi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks this lgtm! xrmx or another Maintainer will also need to review this.

@xrmx xrmx moved this from Ready for review to Approved PRs that need fixes in Python PR digest Feb 20, 2026
Copy link
Copy Markdown
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@xrmx xrmx moved this from Approved PRs that need fixes to Approved PRs in Python PR digest Feb 20, 2026
@xrmx xrmx merged commit 413c98e into open-telemetry:main Feb 20, 2026
771 checks passed
@github-project-automation github-project-automation bot moved this from Approved PRs to Done in Python PR digest Feb 20, 2026
@pauloxnet pauloxnet mentioned this pull request Mar 4, 2026
6 tasks
sightseeker added a commit to sightseeker/opentelemetry-python-contrib that referenced this pull request Mar 11, 2026
…pen-telemetry#4116)

* test(mysql): provide concrete DBAPI connection attributes in mocks

* test(mysql): pass concrete attributes via MagicMock helpers

* test(mysql): refactor mocks and remove redundant attribute assignments

* changelog: add mysql test mock fix entry

* test(mysql): refactor SQL commenter mocks into helper

* test(mysql): refactor SQL commenter mocks into helper

- Introduce make_mysql_commenter_mocks helper
- Remove duplicated MagicMock setup
- Preserve test assertions and behavior
- Improve readability and maintainability

* test(mysql): use concrete DBAPI connection attributes in mocks to fix attribute type warnings

* Update instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py

---------

Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

opentelemetry-instrumentation-mysql: warnings on attributes with wrong type in tests

3 participants