Skip to content

Support format specs in log path templates - #1097

Open
itzzdev09 wants to merge 1 commit into
getslash:developfrom
itzzdev09:log-subpath-format-specs
Open

itzzdev09 wants to merge 1 commit into
getslash:developfrom
itzzdev09:log-subpath-format-specs

Conversation

@itzzdev09

Copy link
Copy Markdown

Fixes #1069.

log.subpath (and the other log path settings) are format strings whose context values are wrapped in _NormalizedObject, which makes them safe to use as path components. The wrapper had no __format__, so any format spec failed: {context.test_classname:.3} raised TypeError: unsupported format string passed to _NormalizedObject.__format__, and the session ended with an error.

_NormalizedObject.__format__ now applies the spec to the already normalized (path-safe) string, so {...:.3} trims, {...:>5} pads, and so on. Values that are numbers are still returned as numbers and keep working with numeric specs, as before.

Added test_log_path_format_specs; it fails without the change (the TypeError above) and passes with it. I ran all of tests/test_logging.py on Windows with Python 3.12: 124 passed, 22 skipped (the skips are existing does not run on windows tests).

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

Successfully merging this pull request may close these issues.

String formatting doesn't seem to be fully supported when using log.subpath

1 participant