Skip to content

Commit

Permalink
fix up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Apr 9, 2024
1 parent 13e3086 commit 5e17f53
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
4 changes: 2 additions & 2 deletions otaclient/app/log_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import requests

from otaclient import otaclient_package_name
import otaclient
from .configs import config as cfg


Expand Down Expand Up @@ -91,7 +91,7 @@ def configure_logging():
# external modules unless reached CRITICAL level.
logging.basicConfig(level=logging.CRITICAL, format=cfg.LOG_FORMAT, force=True)
# NOTE: set the <loglevel> to the otaclient package root logger
_otaclient_logger = logging.getLogger(otaclient_package_name)
_otaclient_logger = logging.getLogger(otaclient.__name__)
_otaclient_logger.setLevel(cfg.DEFAULT_LOG_LEVEL)

# configure each sub loggers
Expand Down
7 changes: 1 addition & 6 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ def patch_main(self, mocker: MockerFixture, tmp_path: Path):
self._sys_exit_mocker = mocker.MagicMock(side_effect=ValueError)
mocker.patch(f"{cfg.MAIN_MODULE_PATH}.sys.exit", self._sys_exit_mocker)

version_file = tmp_path / "version.txt"
version_file.write_text(FIRST_LINE_LOG)
mocker.patch(f"{cfg.MAIN_MODULE_PATH}.EXTRA_VERSION_FILE", version_file)

@pytest.fixture
def background_process(self):
def _waiting():
Expand All @@ -52,12 +48,11 @@ def _waiting():
finally:
_p.kill()

def test_main_with_version(self, caplog: LogCaptureFixture):
def test_main(self, caplog: LogCaptureFixture):
from otaclient.app.main import main

main()
assert caplog.records[0].msg == "started"
assert caplog.records[1].msg == FIRST_LINE_LOG
assert Path(otaclient_cfg.OTACLIENT_PID_FILE).read_text() == f"{os.getpid()}"

def test_with_other_otaclient_started(self, background_process):
Expand Down

0 comments on commit 5e17f53

Please sign in to comment.