nav
nav copied to clipboard
Stop resource leakage when reading conf files
This should fix the annoying ResourceWarnings coming through during the test suite:
/source/python/nav/config.py:339: ResourceWarning: unclosed file <_io.TextIOWrapper name='/source/.tox/integration-py37-django32/etc/nav.conf' mode='r' encoding='utf-8'>
NAV_CONFIG = read_flat_config('nav.conf')
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/source/python/nav/django/settings.py:36: ResourceWarning: unclosed file <_io.TextIOWrapper name='/source/.tox/integration-py37-django32/etc/webfront/webfront.conf' mode='r' encoding='utf-8'>
_webfront_config = getconfig('webfront/webfront.conf')
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/source/python/nav/db/__init__.py:104: ResourceWarning: unclosed file <_io.TextIOWrapper name='/source/.tox/integration-py37-django32/etc/db.conf' mode='r' encoding='utf-8'>
conf = config.read_flat_config('db.conf')
ResourceWarning: Enable tracemalloc to get the object allocation traceback
This PR just ensures we wrap the config-reading code in a context manager so the config files always end up being closed.
Kudos, SonarCloud Quality Gate passed!
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
Codecov Report
Merging #2451 (743de9d) into master (26c69f1) will increase coverage by
0.00%
. The diff coverage is90.47%
.
@@ Coverage Diff @@
## master #2451 +/- ##
=======================================
Coverage 52.72% 52.73%
=======================================
Files 552 552
Lines 40186 40188 +2
=======================================
+ Hits 21190 21192 +2
Misses 18996 18996
Impacted Files | Coverage Δ | |
---|---|---|
python/nav/config.py | 64.96% <90.47%> (+0.45%) |
:arrow_up: |
Test results
12 files 12 suites 12m 3s :stopwatch: 3 088 tests 2 992 :heavy_check_mark: 96 :zzz: 0 :x: 8 739 runs 8 451 :heavy_check_mark: 288 :zzz: 0 :x:
Results for commit 743de9d0.
For the functional tests this error message still appears:
/source/tests/functional/conftest.py:30: ResourceWarning: unclosed file <_io.BufferedWriter name='reports/gunicorn.log'>
start_gunicorn()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
For the functional tests this error message still appears:
/source/tests/functional/conftest.py:30: ResourceWarning: unclosed file <_io.BufferedWriter name='reports/gunicorn.log'> start_gunicorn() ResourceWarning: Enable tracemalloc to get the object allocation traceback
Possibly, but this is not a config file leakage, it's part of the test suite setup, and does not affect production code (i.e. separate PR, at best)