From 965231eaff9135717dffb0aae007dd66e3f6606b Mon Sep 17 00:00:00 2001 From: Dor-bl <59066376+Dor-bl@users.noreply.github.com> Date: Sun, 19 Apr 2026 20:36:34 +0000 Subject: [PATCH] fix: replace assert with ValueError for state validation The use of `assert` for application logic or state checking is discouraged because assertions are removed when Python runs with optimization (-O). This change replaces `assert self.caps` with an explicit `if` check that raises `ValueError`, ensuring that the driver capabilities are always validated even in optimized environments. --- appium/webdriver/webdriver.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 06801313..5ae6b9ab 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -303,7 +303,8 @@ def _update_command_executor(self, keep_alive: bool) -> None: direct_port = 'directConnectPort' direct_path = 'directConnectPath' - assert self.caps, 'Driver capabilities must be defined' + if not self.caps: + raise ValueError('Driver capabilities must be defined') if not {direct_protocol, direct_host, direct_port, direct_path}.issubset(set(self.caps)): message = 'Direct connect capabilities from server were:\n' for key in [direct_protocol, direct_host, direct_port, direct_path]: