Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions test/unit/common/logger_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import sys
from collections.abc import Iterator

import pytest

from appium.common.logger import logger, setup_logger


@pytest.fixture(autouse=True)
def restore_logger() -> Iterator[None]:
# setup_logger mutates the shared module logger, so put it back after each test.
handlers = list(logger.handlers)
level = logger.level
propagate = logger.propagate
yield
logger.handlers[:] = handlers
logger.setLevel(level)
logger.propagate = propagate


def test_setup_logger_default() -> None:
handlers_before = list(logger.handlers)

setup_logger()

assert logger.propagate is False
assert logger.level == logging.NOTSET
assert len(logger.handlers) == len(handlers_before) + 1

new_handler = logger.handlers[-1]
assert isinstance(new_handler, logging.StreamHandler)
assert new_handler.stream == sys.stderr


def test_setup_logger_custom_level() -> None:
handlers_before = list(logger.handlers)

setup_logger(level=logging.DEBUG)

assert logger.propagate is False
assert logger.level == logging.DEBUG
assert len(logger.handlers) == len(handlers_before) + 1

new_handler = logger.handlers[-1]
assert isinstance(new_handler, logging.StreamHandler)
assert new_handler.stream == sys.stderr