diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8df3ca7f..2119bfad 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,6 +11,10 @@ permissions: jobs: release: + # Releases are cut from the upstream repository only. Without this guard the + # workflow also runs on forks, where semantic-release rewrites the version in + # pyproject.toml, commits to the default branch and attempts a PyPI upload. + if: github.repository == 'appium/python-client' runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 diff --git a/appium/webdriver/appium_service.py b/appium/webdriver/appium_service.py index fe34d869..a28bf410 100644 --- a/appium/webdriver/appium_service.py +++ b/appium/webdriver/appium_service.py @@ -181,7 +181,8 @@ def is_listening(self) -> bool: if not self.is_running: return False - assert self._cmd + if not self._cmd: + raise AppiumServiceError('Appium service command has not been initialized') try: return is_service_listening( _make_server_url(self._cmd), diff --git a/test/unit/webdriver/appium_service_test.py b/test/unit/webdriver/appium_service_test.py index d0826c8f..466afad4 100644 --- a/test/unit/webdriver/appium_service_test.py +++ b/test/unit/webdriver/appium_service_test.py @@ -53,3 +53,17 @@ def advance_time(seconds): assert service.is_listening is expected_result assert clock.perf_counter.return_value == expected_elapsed assert connection.request.call_args_list == [call('HEAD', 'http://127.0.0.1:4723/status')] * expected_requests + + def test_is_listening_raises_error_when_cmd_is_empty(self): + service = AppiumService() + process = Mock() + process.poll.return_value = None + service._process = process + service._cmd = [] + + with pytest.raises(appium_service.AppiumServiceError, match='Appium service command has not been initialized'): + _ = service.is_listening + + def test_is_listening_returns_false_when_not_running(self): + service = AppiumService() + assert service.is_listening is False