mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Revert log factory after test run
This commit is contained in:
parent
541c703191
commit
d316759729
2 changed files with 14 additions and 11 deletions
|
@ -132,18 +132,16 @@ class SaltColorLogRecord(SaltLogRecord):
|
|||
def __init__(self, *args, **kwargs):
|
||||
SaltLogRecord.__init__(self, *args, **kwargs)
|
||||
|
||||
# Make sure the name is not a None object so it will format correctly
|
||||
if self.name is None:
|
||||
self.name = ""
|
||||
|
||||
reset = TextFormat("reset")
|
||||
clevel = LOG_COLORS["levels"].get(self.levelname, reset)
|
||||
cmsg = LOG_COLORS["msgs"].get(self.levelname, reset)
|
||||
|
||||
self.colorname = "{}[{:<17}]{}".format(LOG_COLORS["name"], self.name, reset)
|
||||
self.colorlevel = "{}[{:<8}]{}".format(clevel, self.levelname, reset)
|
||||
self.colorname = "{}[{:<17}]{}".format(
|
||||
LOG_COLORS["name"], str(self.name), reset
|
||||
)
|
||||
self.colorlevel = "{}[{:<8}]{}".format(clevel, str(self.levelname), reset)
|
||||
self.colorprocess = "{}[{:>5}]{}".format(
|
||||
LOG_COLORS["process"], self.process, reset
|
||||
LOG_COLORS["process"], str(self.process), reset
|
||||
)
|
||||
self.colormsg = "{}{}{}".format(cmsg, self.getMessage(), reset)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import os
|
|||
import sys
|
||||
|
||||
import pytest
|
||||
from salt._logging.impl import get_log_record_factory, set_log_record_factory
|
||||
from salt.cli.api import SaltAPI
|
||||
|
||||
|
||||
|
@ -10,13 +11,17 @@ def test_start_shutdown(monkeypatch, tmp_path):
|
|||
pid_file = str(tmp_path / "pid_file")
|
||||
log_file = str(tmp_path / "log_file")
|
||||
api = SaltAPI()
|
||||
orig_factory = get_log_record_factory()
|
||||
with pytest.raises(SystemExit):
|
||||
# testing environment will fail if we use default pidfile
|
||||
# overwrite sys.argv so salt-api does not use testing args
|
||||
monkeypatch.setattr(
|
||||
"sys.argv", [sys.argv[0], "--pid-file", pid_file, "--log-file", log_file]
|
||||
)
|
||||
api.start()
|
||||
assert os.path.isfile(pid_file)
|
||||
assert os.path.isfile(log_file)
|
||||
api.shutdown()
|
||||
try:
|
||||
api.start()
|
||||
assert os.path.isfile(pid_file)
|
||||
assert os.path.isfile(log_file)
|
||||
api.shutdown()
|
||||
finally:
|
||||
set_log_record_factory(orig_factory)
|
||||
|
|
Loading…
Add table
Reference in a new issue