Skip to content

Option to show log output when running individual tests #1093

Closed

Description

@joshuagl

In #1083 @sechkova dug into the current logging behaviour and documented that

  1. Executing the tests by aggregate_tests.py buffers the output on a successful run.
  2. Executing a test "by hand", the logging output remains hidden until an error occurs.

IMNSHO we should only buffer individual tests run by hand when the -b command-line option is passed.

Activity

  1. jku commented on Aug 3, 2020

    @jku
    Member

    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. joshuagl commented on Aug 4, 2020

    @joshuagl
    MemberAuthor

    That would also be fine, so long as we can toggle easily.

  3. jku commented on Aug 6, 2020

    @jku
    Member

    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?

  4. changed the title [-]Show log output when running individual tests[/-] [+]Option to show log output when running individual tests[/+] on Aug 10, 2020
  5. jku commented on Aug 13, 2020

    @jku
    Member

    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
    • had to set default level to CRITICAL since we currently log so much on ERROR (issue logging level consistency #1108 )
    • 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?
  6. added 2 commits that reference this issue on Sep 15, 2020
    647e3e0
    03b15fb
  7. added a commit that references this issue on Sep 28, 2020
    bd53289
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions