-
Notifications
You must be signed in to change notification settings - Fork 421
version 1.7.0 and above broke pytest verbose output #262
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
Comments
Hey @silvestriluca, thank you for raising this -- It's definitely an interesting one. I did some quick analysis before I get back to this on Friday before the 1.10.0 release, and I can't see anything obvious at the moment --- It's almost as if our logging filter is suppressing its output despite Pytest logger being completely independent for Live Log feature. What we did in 1.7.0 was basically add a filter to all existing loggers (root in particular) to filter out any child logger messages from our Logger, and that was deliberate to not impact any other existing loggers but our child ones. here are my notes for now before I get back to it. Pytest Live Log Logger registered: 1.9.1 version
1.6.1 version
|
Forgot to mention, the log records are being registered as expected - use -s option to see them, but for some reason it doesn't without |
Hello @heitorlessa . Thank you for the quick reply and preliminary analysis. |
Alright @silvestriluca, finally found the why and it's not pretty - Pytest Live Log feature changes the logging root stream with a ColorFormatter formatter to propagate what any Logger logs (hence why you see in the tests). Why this happens1. We filter out any duplicated logs coming from our Logger namespace This allows us to have child loggers sharing changes bi-directionally. For example, if a Parent logger adds a new structured key, it'll reflect in the Child and vice-versa e.g. folks using multiple loggers across multiple files or in Layers 2. We cannot easily differentiate between Pytest Live Log messages Log filters are applied right after a Log Record is created[1], and until it reaches the handler space[2] there's not much contextual information that can be injected to differentiate between the two. It's a great feature of Pytest, that's for sure, but it leaves no trace that I can think of to make these calls. Options as of now
What would you suggest @silvestriluca? I'd vote for an env var [1] Log record originally produced compared with Pytest Live Log record that will be suppressed in the next step. Powertools Log record {
'args': (),
'created': 1610706539.410131,
'exc_info': None,
'exc_text': None,
'filename': 'main.py',
'funcName': 'handler',
'levelname': 'ERROR',
'levelno': 40,
'lineno': 11,
'message': 'Some error level log',
'module': 'main',
'msecs': 410.13097763061523,
'msg': 'Some error level log',
'name': 'Main function',
'pathname': '/private/tmp/bug-262/main.py',
'process': 97653,
'processName': 'MainProcess',
'relativeCreated': 504.8849582672119,
'stack_info': None,
'thread': 4557233600,
'threadName': 'MainThread'
} Pytest live log record {
'args': (),
'created': 1610706539.410131,
'exc_info': None,
'exc_text': None,
'filename': 'main.py',
'funcName': 'handler',
'levelname': 'ERROR',
'levelno': 40,
'lineno': 11,
'message': 'Some error level log',
'module': 'main',
'msecs': 410.13097763061523,
'msg': 'Some error level log',
'name': 'Main function',
'pathname': '/private/tmp/bug-262/main.py',
'process': 97653,
'processName': 'MainProcess',
'relativeCreated': 504.8849582672119,
'stack_info': None,
'thread': 4557233600,
'threadName': 'MainThread'
} |
Hello @heitorlessa . Great analysis, kudos for that!
What do you think? |
Perfect - I'll see if I can ship this with 1.10 early next week, or as a fast follow by next Friday then ;) |
Done - Could you review the PR #268 to see if the messaging is right before we ship it tomorrow @silvestriluca? Thank you! |
@heitorlessa Docs are ok for me. |
…262 (#268) * feat: add flag to disable log deduplication filter #262 * docs: add new env var, explicit warning on its use Signed-off-by: heitorlessa <[email protected]> * chore: address Nicolas' feedback on comment example
hey @silvestriluca - This is now available on 1.10 on PyPi and on SAR :) Closing this now, and thank you for reporting it one more time |
Problem description
During local tests is not infrequent to use Pytest with live log call output to watch logs as they are emitted and to help in debugging activities. The command to have this "verbose" output is the following
pytest -o log_cli=1
Until aws-lambda-powertools 1.6.1 the command worked fine.
Since version 1.7.0 all pytest live log call outputs are missing.
Expected behaviour
All function/test live log call outputs should be visible when issuing
pytest -o log_cli=1
Current behaviour
No live log call outputs when issuing
pytest -o log_cli=1
and using powertools 1.7.0 or aboveHow to reproduce
I've provided a simple gist to reproduce the issue.
Working scenario
python3 -m venv v-env-pt161
v-env-pt161
virtual environmentpip install -r requirements_powertools161.txt
to install pytest and powertools v1.6.1pytest -o log_cli=1
As you can see, all log lines appear as expected, with proper errorlevel => this powertool version works
Broken scenario
python3 -m venv v-env-ptlatest
v-env-ptlatest
virtual environmentpip install -r requirements.txt
to install pytest and latest powertools (v1.9.1)pytest -o log_cli=1
Possible cause
According to Powertools changelog, version 1.7.0 introduced the following bugfix:
My guess is that this somehow steals the log handler from pytest, making
-o log_cli=1
options useless.Suggested fix implementation
Since this bug is relevant only during local unit tests and it was introduced with version 1.7.0, setting an environment variable that restores the pre-v1.7.0 log behaviour and that can be used only during local tests could do the job.
Environment
The text was updated successfully, but these errors were encountered: