Skip to content

Commit e40eca0

Browse files
committed
fix: use safe module access in ensureRootLogger for parallel test execution
In parallel test execution with stitched builds, sys.modules[__name__] can raise KeyError if the module isn't yet registered in sys.modules due to race conditions. Use sys.modules.get(__name__) instead with a None check, following the same pattern used elsewhere in the codebase (line 734). This fixes intermittent test failures in ensureRootLogger when tests run in parallel with pytest -n auto in stitched mode.
1 parent 2323bb8 commit e40eca0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/apathetic_logging/logger.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,9 @@ class MyLogger(apathetic_logging.Logger):
950950

951951
# Mark that user has explicitly configured the root logger
952952
# This tells extendLoggingModule() not to touch the root logger
953-
current_module = sys.modules[__name__]
954-
current_module._root_logger_user_configured = True # type: ignore[attr-defined] # noqa: SLF001
953+
current_module = sys.modules.get(__name__)
954+
if current_module is not None:
955+
current_module._root_logger_user_configured = True # type: ignore[attr-defined] # noqa: SLF001
955956

956957
def determineLogLevel(
957958
self,

0 commit comments

Comments
 (0)