Skip to content

Commit

Permalink
warnings: close logconfig_json after parse
Browse files Browse the repository at this point in the history
  • Loading branch information
pajod committed Aug 17, 2024
1 parent 903792f commit 4c279f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gunicorn/glogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ def setup(self, cfg):
config = CONFIG_DEFAULTS.copy()
if os.path.exists(cfg.logconfig_json):
try:
config_json = json.load(open(cfg.logconfig_json))
with open(cfg.logconfig_json) as f:
config_json = json.load(f)
config.update(config_json)
dictConfig(config)
except (
Expand Down
16 changes: 16 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import datetime
import tempfile
from types import SimpleNamespace

import pytest

from gunicorn.config import Config
from gunicorn.glogging import Logger
from unittest import mock


@mock.patch('json.load')
def test_json_loaded(load):
with tempfile.NamedTemporaryFile() as f:
f.write("{}".encode())
f.flush()

cfg = Config()
cfg.set("logconfig_json", f.name)
logger = Logger(cfg)
logger.debug("foo")

load.assert_called_once()


def test_atoms_defaults():
Expand Down

0 comments on commit 4c279f3

Please sign in to comment.