You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been using PTF with the default logging settings. This configuration has all testcases write to the same log file (ptf.log).
I have noticed that from the second testcase onwards, all log entries are duplicated. For example:
20:05:24.469 root : INFO : ** START TEST CASE session_hello.HelloWhenSendRefreshShouldSucceed
20:05:24.469 root : INFO : ** START TEST CASE session_hello.HelloWhenSendRefreshShouldSucceed
After debugging, I determined that src/ptf/init.py - open_logfile is not cleaning up the handlers from the previous test case properly.
This function iterates through the existing handlers and removes them:
# Remove any existing handlers
for handler in logger.handlers:
logger.removeHandler(handler)
handler.close()
Unfortunately, Python does not support mutating a list while iterating through it with a for loop. The result was that some of the handlers were not deleted.
Instead, we need to create a copy of the list before modifying. The easiest way is with a slice as described by:
I have been using PTF with the default logging settings. This configuration has all testcases write to the same log file (ptf.log).
I have noticed that from the second testcase onwards, all log entries are duplicated. For example:
After debugging, I determined that src/ptf/init.py - open_logfile is not cleaning up the handlers from the previous test case properly.
This function iterates through the existing handlers and removes them:
Unfortunately, Python does not support mutating a list while iterating through it with a for loop. The result was that some of the handlers were not deleted.
Instead, we need to create a copy of the list before modifying. The easiest way is with a slice as described by:
https://stackoverflow.com/questions/41443336/python-2-7-remove-handler-object-or-logger
The code would then become:
I am using Python 2.7 in my development environment.
The text was updated successfully, but these errors were encountered: