Skip to content

PYTHON-5774 Increase daemon.py coverage to 63%#2759

Open
aclark4life wants to merge 2 commits intomongodb:masterfrom
aclark4life:PYTHON-5774
Open

PYTHON-5774 Increase daemon.py coverage to 63%#2759
aclark4life wants to merge 2 commits intomongodb:masterfrom
aclark4life:PYTHON-5774

Conversation

@aclark4life
Copy link
Copy Markdown
Contributor

PYTHON-5774

Changes in this PR

  • Add test/test_daemon.py with 13 unit tests covering _popen_wait, _silence_resource_warning, _spawn, _spawn_daemon_double_popen, and _spawn_daemon on both Unix and Windows
  • Cover timeout handling, FileNotFoundError warnings, double-Popen intermediate process mechanics, and the sys.executable fallback path
  • Add Windows-specific tests verifying DETACHED_PROCESS flag, devnull stdio redirection, and the constant value 0x00000008
  • Add TestMainBlock verifying the script exits with code 0 when run directly

Test Plan

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

Add test/test_daemon.py covering previously untested branches:

- _popen_wait: success, TimeoutExpired, and None timeout
- _silence_resource_warning: sets returncode to 0, no-op for None
- _spawn (Unix): success and FileNotFoundError warning
- _spawn_daemon_double_popen: intermediate args, wait timeout, timeout swallowing
- _spawn_daemon (Unix): double-Popen path and sys.executable fallback
- _spawn_daemon (Windows): success and FileNotFoundError warning (skipped on Unix)
- __main__ block: runs as script and exits with code 0
Expand TestSpawnDaemonWindows with three new tests:

- test_uses_detached_process_flag: verifies DETACHED_PROCESS is passed
  as creationflags to Popen so the child survives parent exit
- test_uses_devnull_for_stdio: verifies stdin/stdout/stderr are all
  redirected to devnull to fully detach from the parent console
- test_detached_process_constant_value: verifies _DETACHED_PROCESS
  equals 0x00000008 per the Windows process creation flag API
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a dedicated unit-test module to increase coverage of pymongo.daemon, focusing on the cross-platform daemon spawning helpers used by client-side encryption.

Changes:

  • Introduces test/test_daemon.py with unit tests for _popen_wait, _silence_resource_warning, and daemon spawning paths on Unix and Windows.
  • Adds coverage for timeout handling, FileNotFoundError warning behavior, and the Unix sys.executable fallback logic.
  • Adds a Unix-only subprocess test that runs pymongo.daemon as a module to exercise the __main__ block behavior.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.87%. Comparing base (f41dd5c) to head (b0c9e08).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2759      +/-   ##
==========================================
+ Coverage   82.33%   87.87%   +5.53%     
==========================================
  Files         141      141              
  Lines       24396    24520     +124     
  Branches     4172     4234      +62     
==========================================
+ Hits        20087    21547    +1460     
+ Misses       3413     2069    -1344     
- Partials      896      904       +8     
Flag Coverage Δ
auth-aws-rhel8-test-auth-aws-rapid-web-identity-python3.14-cov 35.02% <ø> (ø)
auth-aws-win64-test-auth-aws-rapid-web-identity-python3.14-cov 35.02% <ø> (ø)
auth-enterprise-macos-test-standard-auth-latest-python3.11-auth-ssl-sharded-cluster-cov 43.82% <ø> (+0.04%) ⬆️
auth-enterprise-rhel8-test-standard-auth-latest-python3.11-auth-ssl-sharded-cluster-cov 43.76% <ø> (ø)
auth-enterprise-win64-test-standard-auth-latest-python3.11-auth-ssl-sharded-cluster-cov 43.77% <ø> (-0.04%) ⬇️
auth-oidc-local-ubuntu-22-test-auth-oidc-default 48.62% <ø> (?)
compression-snappy-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.08% <ø> (ø)
compression-snappy-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.39% <ø> (+<0.01%) ⬆️
compression-snappy-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.53% <ø> (ø)
compression-snappy-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (ø)
compression-zlib-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.09% <ø> (+<0.01%) ⬆️
compression-zlib-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.39% <ø> (ø)
compression-zlib-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.53% <ø> (ø)
compression-zlib-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (+0.01%) ⬆️
compression-zstd-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.10% <ø> (+0.02%) ⬆️
compression-zstd-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.39% <ø> (ø)
compression-zstd-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.53% <ø> (ø)
compression-zstd-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.75% <ø> (+<0.01%) ⬆️
compression-zstd-ubuntu-22-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.72% <ø> (+0.01%) ⬆️
coverage-report-coverage-report 87.84% <ø> (+5.69%) ⬆️
disable-test-commands-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.09% <ø> (+0.01%) ⬆️
disable-test-commands-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.41% <ø> (+0.01%) ⬆️
disable-test-commands-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.53% <ø> (ø)
disable-test-commands-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (+0.01%) ⬆️
encryption-crypt_shared-macos-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.73% <ø> (?)
encryption-crypt_shared-macos-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.60% <ø> (?)
encryption-crypt_shared-macos-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.41% <ø> (?)
encryption-crypt_shared-rhel8-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.74% <ø> (?)
encryption-crypt_shared-rhel8-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.49% <ø> (?)
encryption-crypt_shared-rhel8-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.42% <ø> (?)
encryption-crypt_shared-win64-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.69% <ø> (?)
encryption-crypt_shared-win64-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.53% <ø> (?)
encryption-crypt_shared-win64-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.50% <ø> (?)
encryption-macos-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.74% <ø> (?)
encryption-macos-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.56% <ø> (?)
encryption-macos-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.44% <ø> (?)
encryption-pyopenssl-rhel8-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 53.40% <ø> (?)
encryption-pyopenssl-rhel8-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 55.17% <ø> (?)
encryption-rhel8-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.74% <ø> (?)
encryption-rhel8-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.48% <ø> (?)
encryption-rhel8-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.41% <ø> (?)
encryption-win64-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.62% <ø> (?)
encryption-win64-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.53% <ø> (?)
encryption-win64-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.46% <ø> (?)
load-balancer-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 48.39% <ø> (?)
mongodb-latest-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 56.93% <ø> (ø)
mongodb-latest-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 55.13% <ø> (+0.02%) ⬆️
mongodb-latest-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 59.37% <ø> (+0.07%) ⬆️
mongodb-latest-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 59.48% <ø> (+0.07%) ⬆️
mongodb-latest-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 61.31% <ø> (+0.01%) ⬆️
mongodb-rapid-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 56.95% <ø> (-0.01%) ⬇️
mongodb-rapid-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 55.12% <ø> (+0.01%) ⬆️
mongodb-rapid-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 59.37% <ø> (+0.07%) ⬆️
mongodb-rapid-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 59.48% <ø> (+0.07%) ⬆️
mongodb-rapid-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 61.29% <ø> (ø)
mongodb-v4.2-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 54.55% <ø> (+0.01%) ⬆️
mongodb-v4.2-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 52.99% <ø> (+0.01%) ⬆️
mongodb-v4.2-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 56.94% <ø> (+0.07%) ⬆️
mongodb-v4.2-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.06% <ø> (+0.07%) ⬆️
mongodb-v4.2-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 54.68% <ø> (+<0.01%) ⬆️
mongodb-v4.4-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 55.01% <ø> (-0.01%) ⬇️
mongodb-v4.4-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 53.35% <ø> (+<0.01%) ⬆️
mongodb-v4.4-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.44% <ø> (+0.07%) ⬆️
mongodb-v4.4-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.53% <ø> (+0.07%) ⬆️
mongodb-v4.4-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 55.08% <ø> (-0.01%) ⬇️
mongodb-v5.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 55.21% <ø> (-0.02%) ⬇️
mongodb-v5.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 53.51% <ø> (-0.01%) ⬇️
mongodb-v5.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.64% <ø> (+0.07%) ⬆️
mongodb-v5.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.76% <ø> (+0.07%) ⬆️
mongodb-v5.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 55.32% <ø> (-0.01%) ⬇️
mongodb-v6.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 55.23% <ø> (-0.03%) ⬇️
mongodb-v6.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 53.52% <ø> (ø)
mongodb-v6.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.66% <ø> (+0.07%) ⬆️
mongodb-v6.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.81% <ø> (+0.07%) ⬆️
mongodb-v6.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 59.62% <ø> (+0.01%) ⬆️
mongodb-v7.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 55.27% <ø> (-0.01%) ⬇️
mongodb-v7.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 53.51% <ø> (ø)
mongodb-v7.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.71% <ø> (+0.07%) ⬆️
mongodb-v7.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.81% <ø> (+0.07%) ⬆️
mongodb-v7.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 59.61% <ø> (+<0.01%) ⬆️
mongodb-v8.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 56.95% <ø> (+<0.01%) ⬆️
mongodb-v8.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 55.11% <ø> (+<0.01%) ⬆️
mongodb-v8.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 59.37% <ø> (+0.07%) ⬆️
mongodb-v8.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 59.48% <ø> (+0.07%) ⬆️
mongodb-v8.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 61.29% <ø> (-0.01%) ⬇️
no-c-ext-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 56.29% <ø> (-0.01%) ⬇️
no-c-ext-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 62.59% <ø> (-0.01%) ⬇️
no-c-ext-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 57.74% <ø> (ø)
no-c-ext-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 55.94% <ø> (-0.01%) ⬇️
ocsp-rhel8-test-ocsp-ecdsa-valid-cert-server-staples-latest-python3.14-cov 34.09% <ø> (ø)
ocsp-rhel8-test-ocsp-rsa-valid-cert-server-staples-latest-python3.14-cov 34.09% <ø> (ø)
pyopenssl-macos-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.64% <ø> (?)
pyopenssl-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.64% <ø> (?)
pyopenssl-win64-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.59% <ø> (?)
stable-api-accept-v2-rhel8-auth-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.09% <ø> (+0.01%) ⬆️
stable-api-accept-v2-rhel8-auth-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (ø)
stable-api-require-v1-rhel8-auth-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.07% <ø> (+<0.01%) ⬆️
stable-api-require-v1-rhel8-auth-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.40% <ø> (-0.02%) ⬇️
stable-api-require-v1-rhel8-auth-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.72% <ø> (ø)
storage-inmemory-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.08% <ø> (ø)
storage-inmemory-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (ø)
test-macos-arm64-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.06% <ø> (-0.01%) ⬇️
test-macos-arm64-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.38% <ø> (-0.01%) ⬇️
test-macos-arm64-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.52% <ø> (ø)
test-macos-arm64-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.71% <ø> (ø)
test-macos-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.05% <ø> (-0.04%) ⬇️
test-macos-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.37% <ø> (ø)
test-macos-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.52% <ø> (+<0.01%) ⬆️
test-macos-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.71% <ø> (-0.01%) ⬇️
test-numpy-macos-arm64-test-numpy-python3.14-python3.14-cov 32.62% <ø> (ø)
test-numpy-macos-test-numpy-python3.14-python3.14-cov 32.62% <ø> (-0.02%) ⬇️
test-numpy-rhel8-test-numpy-python3.14-python3.14-cov ?
test-numpy-win32-test-numpy-python3.14-python3.14-cov 32.59% <ø> (ø)
test-numpy-win64-test-numpy-python3.14-python3.14-cov 32.60% <ø> (ø)
test-win32-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 54.94% <ø> (ø)
test-win32-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.38% <ø> (+0.02%) ⬆️
test-win32-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.46% <ø> (ø)
test-win32-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.58% <ø> (+0.01%) ⬆️
test-win64-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 54.92% <ø> (-0.03%) ⬇️
test-win64-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.36% <ø> (ø)
test-win64-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.46% <ø> (ø)
test-win64-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.58% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants