Skip to content

version 1.7.0 and above broke pytest verbose output #262

Closed
@silvestriluca

Description

@silvestriluca

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.

  1. Clone the following gist: https://gist.github.com/silvestriluca/95352eb38587cb6bc333f8ec790fb22a
  2. Navigate to the repo folder

Working scenario

  1. Set a virtual environment: python3 -m venv v-env-pt161
  2. Activate the v-env-pt161 virtual environment
  3. pip install -r requirements_powertools161.txt to install pytest and powertools v1.6.1
  4. Run pytest -o log_cli=1
  5. You should see the following output:

Good

As you can see, all log lines appear as expected, with proper errorlevel => this powertool version works

Broken scenario

  1. Now set a new virtual environment: python3 -m venv v-env-ptlatest
  2. Activate the v-env-ptlatest virtual environment
  3. pip install -r requirements.txt to install pytest and latest powertools (v1.9.1)
  4. Run pytest -o log_cli=1
  5. You should see the following output. BadAs you can see, the logs are missing => this powertool version doesn't work
  6. 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

bugSomething isn't working

Type

No type

Projects

Status

Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions