Fix integration test warnings and restore container log streaming - #98
Open
oysand wants to merge 2 commits into
Open
Fix integration test warnings and restore container log streaming#98oysand wants to merge 2 commits into
oysand wants to merge 2 commits into
Conversation
testcontainers.postgres is a re-export shim that emits a DeprecationWarning on import. The implementation now lives in testcontainers.community.postgres, which exposes an identical PostgresContainer.
The log streaming thread was started in __init__, before the container existed. Its first statement called get_wrapped_container(), which raises ContainerStartException while _container is None rather than returning None as an earlier testcontainers API did. The thread therefore died immediately every time, so container logs were never streamed and each container produced a PytestUnhandledThreadExceptionWarning. Start the thread from start() instead, once the container is guaranteed to exist, which also removes the need to poll for it. Mark it as a daemon, stop and join it in stop(), and tolerate the stream failing when the container is removed during teardown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The integration test suite emits 54 warnings on
main(c2dca4b). Investigating them turned up a real defect: container log streaming has never worked.PytestUnhandledThreadExceptionWarning(39 warnings)StreamLoggingDockerContainerstarted its log streaming thread in__init__, i.e. before.start()had been called, so_containerwas stillNone. The thread then began with:That guard assumes the accessor returns
Nonewhen the container is not yet started, which was true of an older testcontainers API. In 4.x it raisesContainerStartExceptioninstead. Every streaming thread therefore died on its first statement, for every container in every test. Thelogger.info(...)call below it was unreachable, which is why-snever showed any container output despite the class existing to provide exactly that.The thread is now started from an overridden
start(), aftersuper().start(), where the container is guaranteed to exist — so the polling loop is unnecessary and is removed. It is also marked as a daemon, andstop()signals it and joins it so pytest cannot observe a dying thread after a test ends.The stream body is wrapped in
try/except:logs(stream=True, follow=True)is a blocking generator that fails when the fixture removes the container during teardown. Without this, fixing the bug above simply converts the warnings into a new batch of the same warnings.DeprecationWarningfromtestcontainers.postgres(15 warnings)That module is now a re-export shim that warns on import; the implementation lives in
testcontainers.community.postgresand exposes an identicalPostgresContainer.Verification
uv run --frozen pytest -s -n auto robotics_integration_tests, on macOS/arm64:Zero warnings alone would not have been sufficient evidence — a silent run would equally mean the thread never ran. The streamed output is the actual acceptance criterion.
Also verified:
alpinecontainer: logs stream, the thread joins cleanly on exit, no exception;log streaming stoppedmessages in the full run, so teardown is genuinely clean rather than having its errors swallowed;1 passed, carrying only the thread warnings that the second commit removes), per the checklist item that every commit runs individually.Notes for reviewers
wait_for_sara_logsusescontainer.get_logs()directly and is unaffected.create_*factories return an unstarted container that callers enter viawith/enter_context, sostart()is always invoked; it returnsselfto keep the chained builder calls working.-s. That is the intended behaviour of this class, and CI only surfaces the output on failure.Checklist