Skip to content

Commit 6ca4cd6

Browse files
committed
Force INFO log level on memory test?
1 parent db37fb4 commit 6ca4cd6

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

tests/test_memory_large_file_transfer_s3.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
import time
3939
import uuid
4040

41-
import boto3
4241
import objgraph
43-
import opentaskpy.otflogging
4442
import psutil
4543
import pytest
4644
from opentaskpy.config.loader import ConfigLoader
@@ -55,6 +53,31 @@
5553
)
5654
os.environ["OTF_NO_THREAD_SLEEP"] = "1" # don't wait 1s between task thread creation
5755

56+
57+
@pytest.fixture(autouse=True)
58+
def _enforce_info_log_level():
59+
"""Ensure INFO log level during this test regardless of collection-time env overrides.
60+
61+
Other test modules set OTF_LOG_LEVEL=DEBUG at module level. Because pytest
62+
imports (collects) all modules before running any test, those assignments
63+
execute after this module's own module-level assignment and leave
64+
OTF_LOG_LEVEL=DEBUG in the environment by the time this test actually runs.
65+
Setting it here (at fixture execution time) guarantees INFO for the duration
66+
of the memory test, which prevents botocore/s3transfer from flooding the
67+
heap with DEBUG log objects and skewing the RSS measurement.
68+
"""
69+
prev = os.environ.get("OTF_LOG_LEVEL")
70+
os.environ["OTF_LOG_LEVEL"] = "INFO"
71+
logging.getLogger().setLevel(logging.INFO)
72+
logging.getLogger("botocore").setLevel(logging.INFO)
73+
logging.getLogger("s3transfer").setLevel(logging.INFO)
74+
yield
75+
if prev is None:
76+
os.environ.pop("OTF_LOG_LEVEL", None)
77+
else:
78+
os.environ["OTF_LOG_LEVEL"] = prev
79+
80+
5881
# ---------------------------------------------------------------------------
5982
# Constants
6083
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)