Fix flaky bluetooth constant tests in test_socket.py for cross-platform compatibility#1
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
Replace sys.platform-based checks with hasattr() checks in testBluetoothConstants. The availability of bluetooth constants depends on compile-time configuration (whether bluetooth headers were present), not on the runtime platform. Using sys.platform caused intermittent failures in CI environments where AF_BLUETOOTH was available but specific bluetooth headers (e.g. bluetooth/bluetooth.h) were not installed during compilation. This aligns the test with the pattern already used for BT_PHY, BT_MODE, and BT_VOICE constants within the same method, and matches the #ifdef guards in Modules/socketmodule.c. Co-Authored-By: cameron bica <bicacameron@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace
sys.platform-based guards withhasattr()checks intestBluetoothConstantsto fix intermittent CI failures.Problem
testBluetoothConstantsinBasicBluetoothTestusessys.platformchecks to decide which bluetooth constants should exist. However, inModules/socketmodule.c, these constants are conditionally compiled using#ifdefpreprocessor guards based on compile-time header availability — not the runtime platform. A Linux CI runner that hasAF_BLUETOOTHbut was compiled withoutbluetooth/bluetooth.h(or specific protocol headers) will fail withAttributeErroron constants likeBTPROTO_HCI,SOL_BLUETOOTH,HCI_DATA_DIR, etc.Fix
Replaced all
sys.platformguards withhasattr(socket, ...)checks, matching the pattern already used within the same method forBT_PHY,BT_MODE, andBT_VOICE. Each constant group now has its ownhasattrguard aligned with the corresponding#ifdefblock insocketmodule.c:BTPROTO_HCI/SOL_HCI— guarded by#ifdef BTPROTO_HCIBTPROTO_L2CAP/SOL_L2CAP— guarded by#ifdef BTPROTO_L2CAPBTPROTO_SCO/SOL_SCO— guarded by#ifdef BTPROTO_SCOSOL_BLUETOOTHgroup (HCI_DEV_NONE, HCI_CHANNEL_*, BT_SECURITY, etc.) — guarded by#ifdef HAVE_BLUETOOTH_BLUETOOTH_HHCI_TIME_STAMP,HCI_DATA_DIR,HCI_FILTER,L2CAP_LM— each has its own#ifdefin the C source, so each gets its ownhasattrguardSO_L2CAP_IMTU,SO_RFCOMM_MTU, etc.) — similarly split by their#ifdefguardsReview checklist
hasattrblock match the#ifdefgroupings inModules/socketmodule.c(e.g.,SOL_HCIis always added alongsideBTPROTO_HCIin C, so bundling them is correct)SOL_BLUETOOTHblock — it bundles many constants under one check; all are under#ifdef HAVE_BLUETOOTH_BLUETOOTH_Hin CHCI_TIME_STAMPwas moved out of theSOL_BLUETOOTHgroup into its ownhasattrcheck (it has a separate#ifdef HCI_TIME_STAMPin C) — verify this is correctL2CAP_LMgroup was moved out of theSOL_BLUETOOTHgroup (it has#ifdef L2CAP_LMin C) — verify this is correctLink to Devin session: https://app.devin.ai/sessions/db273c93b8b14c5cb2ae9ee6c80f4716
Requested by: @Cameronthhacker