GenomicMedLab / software-templates

Cookiecutter templates for lab software projects
MIT License
0 stars 0 forks source link

Logging configuration in Python tests #33

Open jsstevenson opened 3 months ago

jsstevenson commented 3 months ago

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.