Skip to content
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

Logging configuration in Python tests #33

Open
jsstevenson opened this issue Jun 11, 2024 · 0 comments
Open

Logging configuration in Python tests #33

jsstevenson opened this issue Jun 11, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@jsstevenson
Copy link
Member

Feature description

Many of our projects make use of AWS and database connection libraries that are VERY verbose on debug logging. This can make it hard to get actually meaningful logs in testing. In a couple of our libraries, we have an option to disable those noisy logs -- the template should optionally include a stub for that.

Use case

make logs readable but enable connection debugging if necessary

Proposed solution

blank version of this

def pytest_addoption(parser):
    """Add custom commands to pytest invocation.
    See https://docs.pytest.org/en/7.1.x/reference/reference.html#parser
    """
    parser.addoption(
        "--verbose-logs",
        action="store_true",
        default=False,
        help="show noisy module logs",
    )


def pytest_configure(config):
    """Configure pytest setup."""
    logging.getLogger(__name__).error(config.getoption("--verbose-logs"))
    if not config.getoption("--verbose-logs"):
        for lib in (
            "botocore",
            "boto3",
            "urllib3.connectionpool",
            "neo4j.pool",
            "neo4j.io",
        ):
            logging.getLogger(lib).setLevel(logging.ERROR)

Alternatives considered

No response

Implementation details

No response

Potential Impact

No response

Additional context

No response

Contribution

Yes, I can create a PR for this feature.

@jsstevenson jsstevenson added the enhancement New feature or request label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant