8000 Testing: `test_log2d.cleanup()` does not work as expected/required · Issue #16 · PFython/log2d · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Testing: test_log2d.cleanup() does not work as expected/required #16

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

Open
MikeDP opened this issue Jan 10, 2023 · 2 comments
Open

Testing: test_log2d.cleanup() does not work as expected/required #16

MikeDP opened this issue Jan 10, 2023 · 2 comments

Comments

@MikeDP
Copy link
Contributor
MikeDP commented Jan 10, 2023

(Re)Work on find is complete pending testing but this has highlighted an issue with test_log2d.cleanup() which may impact testing in other areas besides find.

In cleanup(), logging.shutdown() does not have the anticipated effect of re-initialising logging. In particular, after shutdown(), logging still contains handlers which end up affecting subsequent Log instances. Thus, the order in which tests are carried out affects the test results.

This is a design feature of logging.shutdown() which is really meant to be used just before application exit: See this from stackoverflow and Python logging docs.

I will look for a solution but (as always) need to learn more about logging first.

Mike

@PFython
Copy link
Owner
PFython commented Jan 10, 2023

Thanks Mike and belated Happy New Year! No urgency for this as .shutdown was only intended as a utility/helper function for the testing docs and isn't a "public" part of the log2d functionality. Having said that, if you have the time and inclination to get to the bottom of things, you'll have truly mastered the built in logging module I think, and others (including me) will benefit from the sum of your learnings :)

All the best,
Pete

@MikeDP
Copy link
Contributor Author
MikeDP commented Jan 10, 2023

Happy New Year also.

You flatterer! The cure seems to be actually in Log.__init__. If you remove any existing handlers before adding the required ones back in, all is well.

Modify __init__ to add

        while len(self.logger.handlers) > 0:
            self.logger.removeHandler(self.logger.handlers[0])

just before the line for handler in self.get_handlers():

This actually fixed another couple of odd behaviours I'd seen - multiple copies of the log message on stdout being a common one.

I'll leave this one to you if that's OK.

Mike

Sign up for free to join this conversation on GitHub. Already have an 431D account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0