Description
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 above
How to reproduce
I've provided a simple gist to reproduce the issue.
- Clone the following gist: https://gist.github.com/silvestriluca/95352eb38587cb6bc333f8ec790fb22a
- Navigate to the repo folder
Working scenario
- Set a virtual environment:
python3 -m venv v-env-pt161
- Activate the
v-env-pt161
virtual environment pip install -r requirements_powertools161.txt
to install pytest and powertools v1.6.1- Run
pytest -o log_cli=1
- You should see the following output:
As you can see, all log lines appear as expected, with proper errorlevel => this powertool version works
Broken scenario
- Now set a new virtual environment:
python3 -m venv v-env-ptlatest
- Activate the
v-env-ptlatest
virtual environment pip install -r requirements.txt
to install pytest and latest powertools (v1.9.1)- Run
pytest -o log_cli=1
- You should see the following output.
As you can see, the logs are missing => this powertool version doesn't work
- Going backwards with powertools versions, you can see that the issue starts with version 1.7.0
Possible cause
According to Powertools changelog, version 1.7.0 introduced the following bugfix:
improv: keeps Lambda root logger handler intact, and add log filter instead to prevent child log records duplication (#198)
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
- Tested with both Python 3.9.1 and 3.8.3
- Pip package
Metadata
Metadata
Assignees
Labels
Type
Projects
Status