Skip to content

tests: caplog assertion depends on global pytest --log-level #1092

@booxter

Description

@booxter

tests/test_bootstrapper.py::test_cache_lookup_resolver_exception_logs_info currently assumes that INFO logs are being captured globally by pytest.

The test calls _download_wheel_from_cache() and then asserts:

assert "did not find wheel for" in caplog.text

But the code under test logs that message at INFO level:

except ResolverException:
    logger.info(
        f"did not find wheel for {resolved_version} in {self.cache_wheel_server_url}"
    )

The test does not call caplog.set_level(...) or caplog.at_level(...), so it only passes when the test runner is configured with a sufficiently low global log level.

Upstream CI currently masks this because the Hatch test script runs pytest with:

pytest --log-level DEBUG

Downstream runners that invoke pytest with default logging behavior can fail on this test. For example, nixpkgs' pytestCheckHook reproduces:

FAILED tests/test_bootstrapper.py::test_cache_lookup_resolver_exception_logs_info
E   AssertionError: assert 'did not find wheel for' in ''

I think the test should request the log level it needs explicitly rather than depending on a runner-wide pytest flag, e.g. with something like:

with caplog.at_level(logging.INFO, logger="fromager.bootstrapper"):
    ...

That would make the test self-contained and avoid CI-specific behavior differences.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions