Skip to content

[py] handle ERROR log level in SeleniumManager - #18287

Open
saiyam-jain-dev wants to merge 3 commits into
SeleniumHQ:trunkfrom
saiyam-jain-dev:py-selenium-manager-error-log
Open

saiyam-jain-dev wants to merge 3 commits into
SeleniumHQ:trunkfrom
saiyam-jain-dev:py-selenium-manager-error-log

Conversation

@saiyam-jain-dev

Copy link
Copy Markdown
Contributor

🔗 Related Issues

💥 What does this PR do?

  1. Forwards ERROR level logs from Selenium Manager output in _process_logs to logger.error(). Previously, _process_logs checked only WARN, DEBUG, and INFO, silently discarding entries with level ERROR.
  2. Updates py/test/unit/selenium/webdriver/common/selenium_manager_tests.py:
    • Adds unit test coverage for _process_logs covering WARN, ERROR, INFO, and DEBUG levels.
    • Mocks Path.is_file in the platform selection tests (test_uses_windows, test_uses_windows_arm64, test_uses_linux, test_uses_linux_aarch64, test_uses_mac, test_uses_freebsd) so the binary path resolution logic is isolated and does not fail on missing foreign platform binaries in a local development environment.

🔧 Implementation Notes

In _get_binary(), compiled_path takes precedence if it exists, otherwise it falls back to the platform specific subfolder in allowed. The unit tests verify the mapping between (sys.platform, platform.machine()) and the target binary path. Mocking Path.is_file to only treat non-common paths as present allows testing this mapping cleanly.

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s): Claude Code / Antigravity
    • What was generated: Identification of the missing ERROR branch in _process_logs and the test case.
    • I reviewed all AI output and can explain the change

🔄 Types of changes

  • Bug fix (backwards compatible)

Selenium Manager outputs structured logs with severity levels (WARN, ERROR, INFO, DEBUG). In Python's _process_logs, entries with level ERROR were previously ignored. They are now forwarded to logger.error.

Also update selenium_manager_tests.py:
- mock Path.is_file in platform binary selection tests so the path resolution logic can be unit-tested without requiring compiled binaries for all foreign platforms to exist locally
- add unit test coverage for _process_logs across all log levels
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@selenium-ci selenium-ci added the C-py Python Bindings label Nov 6, 2026
@diemol
diemol requested a review from cgoldberg November 9, 2026 12:10
@diemol

diemol commented Nov 9, 2026

Copy link
Copy Markdown
Member

@saiyam-jain-dev did you run tests for this one locally?

Signed-off-by: Saiyam Jain <jimisierra2@gmail.com>
@saiyam-jain-dev

Copy link
Copy Markdown
Contributor Author

@diemol Yes, all 15 tests in py/test/unit/selenium/webdriver/common/selenium_manager_tests.py pass locally, including the est_process_logs case covering WARN, ERROR, INFO, and DEBUG output.

The previous CI failure was caused by a trailing blank line at the end of selenium_manager_tests.py that tripped the format check. That was fixed in commit d7c11d, and both
uff check and
uff format --check are clean.

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Platform tests miss wrong binary paths 📘 Rule violation ☼ Reliability
Description
The six platform selection tests replace Path.is_file with lambda p: p.parent.name != "common",
a fake filesystem that reports any path outside a common folder as present, so _get_binary is no
longer checked against real file existence. A wrong platform subfolder in the allowed mapping
would still pass these tests whenever its parent folder is not named common, and the mock applies
to every platform test in the suite.
Code

py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[54]

+    monkeypatch.setattr(Path, "is_file", lambda p: p.parent.name != "common")
Evidence
The added is_file lambda stands in for the real filesystem check that _get_binary performs,
encoding a folder-name assumption instead of the actual package layout. The PR adds this mock to all
six platform tests, so none of them verify that the resolved binary exists at the mapped location.

py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[54-54]
py/selenium/webdriver/common/selenium_manager.py[90-130]
AGENTS.md: Prefer Small Unit Tests and Avoid Mocks

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The platform selection tests in `py/test/unit/selenium/webdriver/common/selenium_manager_tests.py` monkeypatch `Path.is_file` with `lambda p: p.parent.name != "common"`. This fakes the filesystem based on a folder-name assumption, so the tests no longer verify that `_get_binary` resolves the real binary path for each platform, and they would miss a wrong mapping in the `allowed` dict.

## Fix Focus Areas
- py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[54-54]
- py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[61-61]
- py/selenium/webdriver/common/selenium_manager.py[90-130]

## Recommended Fix
Replace the `is_file` lambda with real file existence: create the expected binary files under a `tmp_path` fixture and point the resolution there, or keep the mock but assert the exact path it was asked about so a wrong mapping still fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗



Informational

2. ERROR-level test would still pass if logged at wrong level 🐞 Bug ⚙ Maintainability
Description
test_process_logs checks only "error message" in caplog.text, which matches the message at any
level, so a regression that routes the ERROR entry to logger.debug or logger.warning would still
pass. The test therefore does not verify the new logger.error routing that this PR adds.
Code

py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[R169-173]

+        SeleniumManager._process_logs(log_items)
+    assert "warning message" in caplog.text
+    assert "error message" in caplog.text
+    assert "info message" in caplog.text
+    assert "debug message" in caplog.text
Evidence
The assertions are plain substring checks on caplog.text, which contains every record regardless
of level. The production change maps ERROR to logger.error, but nothing asserts caplog.records
levels, so the mapping itself is untested.

py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[159-173]
py/selenium/webdriver/common/selenium_manager.py[166-172]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

Issue description
The test `test_process_logs` in py/test/unit/selenium/webdriver/common/selenium_manager_tests.py only checks that each message substring appears in `caplog.text`. This does not confirm that the ERROR entry is emitted at ERROR level, so a regression to a lower level would pass.

Fix Focus Areas
- py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[159-173]
- py/selenium/webdriver/common/selenium_manager.py[166-172]

Recommended Fix
After calling `SeleniumManager._process_logs(log_items)`, assert on `caplog.records`, for example `levels = {r.getMessage(): r.levelno for r in caplog.records}` and check `levels["error message"] == logging.ERROR`, `levels["warning message"] == logging.WARNING`, and the INFO and DEBUG entries map to `logging.DEBUG`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Web pages:
  +2 more
✅ REVIEW.md
Review mode: Auto: 🚀 Fast: Two-line localized logging branch plus test-only mocks; low risk.

Grey Divider

Tip of the day
💡 Did you know, you can see how risky a PR is at a glance with blast radius labels

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo



def test_uses_windows(monkeypatch):
monkeypatch.setattr(Path, "is_file", lambda p: p.parent.name != "common")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remediation recommended

1. Platform tests miss wrong binary paths 📘 Rule violation ☼ Reliability

The six platform selection tests replace Path.is_file with lambda p: p.parent.name != "common",
a fake filesystem that reports any path outside a common folder as present, so _get_binary is no
longer checked against real file existence. A wrong platform subfolder in the allowed mapping
would still pass these tests whenever its parent folder is not named common, and the mock applies
to every platform test in the suite.
Agent Prompt
## Issue description
The platform selection tests in `py/test/unit/selenium/webdriver/common/selenium_manager_tests.py` monkeypatch `Path.is_file` with `lambda p: p.parent.name != "common"`. This fakes the filesystem based on a folder-name assumption, so the tests no longer verify that `_get_binary` resolves the real binary path for each platform, and they would miss a wrong mapping in the `allowed` dict.

## Fix Focus Areas
- py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[54-54]
- py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[61-61]
- py/selenium/webdriver/common/selenium_manager.py[90-130]

## Recommended Fix
Replace the `is_file` lambda with real file existence: create the expected binary files under a `tmp_path` fixture and point the resolution there, or keep the mock but assert the exact path it was asked about so a wrong mapping still fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

Comment on lines +169 to +173
SeleniumManager._process_logs(log_items)
assert "warning message" in caplog.text
assert "error message" in caplog.text
assert "info message" in caplog.text
assert "debug message" in caplog.text

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Informational

2. Error-level test would still pass if logged at wrong level 🐞 Bug ⚙ Maintainability

test_process_logs checks only "error message" in caplog.text, which matches the message at any
level, so a regression that routes the ERROR entry to logger.debug or logger.warning would still
pass. The test therefore does not verify the new logger.error routing that this PR adds.
Agent Prompt
Issue description
The test `test_process_logs` in py/test/unit/selenium/webdriver/common/selenium_manager_tests.py only checks that each message substring appears in `caplog.text`. This does not confirm that the ERROR entry is emitted at ERROR level, so a regression to a lower level would pass.

Fix Focus Areas
- py/test/unit/selenium/webdriver/common/selenium_manager_tests.py[159-173]
- py/selenium/webdriver/common/selenium_manager.py[166-172]

Recommended Fix
After calling `SeleniumManager._process_logs(log_items)`, assert on `caplog.records`, for example `levels = {r.getMessage(): r.levelno for r in caplog.records}` and check `levels["error message"] == logging.ERROR`, `levels["warning message"] == logging.WARNING`, and the INFO and DEBUG entries map to `logging.DEBUG`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

@diemol

diemol commented Nov 9, 2026

Copy link
Copy Markdown
Member

@saiyam-jain-dev please check Qodo's comments.

This branch has not been deployed

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

Labels

C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants