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
{{ message }}
Repository navigation
Option to show log output when running individual tests #1093
I'd prefer that the test log level was easily modifiable (like V=DEBUG python3 test_updater.py) so the default could be practically silent but tricky issues were easy to debug.
2. Executing a test "by hand", the logging output remains hidden until an error occurs.
This is untrue AFAICT: the output is same on error or no error (in an error case there might be more high level output of course, but same logger levels get printed). We do not initialize logging at all when tests are run individually: It think the default is to only print WARNING and above.
We could initialize the logging based on a env variable (or maybe an argv option) in each if __name__ == '__main__': ... but I would expect this was an issue where python folks would have a Best Practice?
I'll open another issue on logging in general but leaving an example that should work right now here:
if __name__ == '__main__':
verbose = '-v' in sys.argv or '--verbose' in sys.argv
loglevel = logging.DEBUG if verbose else logging.CRITICAL
logging.basicConfig()
tuf.log.set_log_level(loglevel)
unittest.main()
Notes:
this is only for running test files manually: it does not and should not affect test runners. They set their own logging policies
this slightly abuses unittest CLI: '--verbose' is actually unittest argument which we're now using as well
tuf.log.set_log_level() seems not that useful: I'd just want to set root logger level and expect all components to follow that (and could do logging.getLogger('tuf').setLevel() if I wanted more control) but tuf forces me to call tuf.log.set_log_level() because there is a default that is not logging.NOTSET. Or is this how libraries are supposed to do logging in python?
Activity
jku commentedon Aug 3, 2020
I'd prefer that the test log level was easily modifiable (like
V=DEBUG python3 test_updater.py) so the default could be practically silent but tricky issues were easy to debug.joshuagl commentedon Aug 4, 2020
That would also be fine, so long as we can toggle easily.
jku commentedon Aug 6, 2020
This is untrue AFAICT: the output is same on error or no error (in an error case there might be more high level output of course, but same logger levels get printed). We do not initialize logging at all when tests are run individually: It think the default is to only print WARNING and above.
We could initialize the logging based on a env variable (or maybe an argv option) in each
if __name__ == '__main__':... but I would expect this was an issue where python folks would have a Best Practice?[-]Show log output when running individual tests[/-][+]Option to show log output when running individual tests[/+]jku commentedon Aug 13, 2020
I'll open another issue on logging in general but leaving an example that should work right now here:
Notes:
logging.getLogger('tuf').setLevel()if I wanted more control) but tuf forces me to call tuf.log.set_log_level() because there is a default that is not logging.NOTSET. Or is this how libraries are supposed to do logging in python?tests: Configure logging for all test files
tests: Configure logging for all test files
tests: Configure logging for all test files