Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PTF creates double log entries #116

Closed
karusher opened this issue Jun 28, 2020 · 3 comments
Closed

PTF creates double log entries #116

karusher opened this issue Jun 28, 2020 · 3 comments

Comments

@karusher
Copy link

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:

https://stackoverflow.com/questions/41443336/python-2-7-remove-handler-object-or-logger

The code would then become:

    # Remove any existing handlers
    for handler in logger.handlers[:]:
        logger.removeHandler(handler)
        handler.close()

I am using Python 2.7 in my development environment.

@saynb
Copy link
Contributor

saynb commented Aug 4, 2020

I think it is the same issue as #104

@karusher
Copy link
Author

karusher commented Aug 4, 2020

I think you are right.

@saynb
Copy link
Contributor

saynb commented Oct 20, 2020

Fixed with #122

@saynb saynb closed this as completed Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants