-
Notifications
You must be signed in to change notification settings - Fork 26
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
log output is not displayed when using a scope other than 'function' #29
Comments
🤔 aye, that's troubling. I wonder if there's a clean way to address this — can it output only the logs that were generated during a particular test? I wonder if we can achieve this by providing a https://github.com/docker/docker-py/blob/master/docker/models/containers.py#L286-L290 |
'since' is already used to only display the logs since the start of the fixture. I think the issue is that the parts of the code before the yield are run once before the first test using the fixture and the parts behind yield are run once only after the final test using the fixture has finished. Instead of doing the logging in the fixture after yield I think we need to look into using different hooks supplied by pytest. But I'm not sure what this would exactly look like. |
I would like to see the logs in realtime, instead of only after the container stopped. Then, and I adding a dedicated thread to print logs in realtime: @pytest.fixture(scope="function")
def fixed_function_scoped_container_getter(function_scoped_container_getter, request):
def callback(service_name):
container = function_scoped_container_getter.get(service_name)
if request.config.getoption("--verbose"):
def threaded_function():
for event in container.logs(stream=True):
print(event.decode("utf-8", errors='replace'), end='')
thread = threading.Thread(target=threaded_function, daemon=True)
thread.start()
return container
return callback I am removing out the code this code because it would print out the log doubled: pytest-docker-compose/src/pytest_docker_compose/__init__.py Lines 172 to 177 in d533499
For this case Related to docker logging: docker/compose#2227 - Improvements to docker-compose logs |
If a user is running multiple tests against one fixture such as a module or class scoped conatiner fixture and the --verbose flag is used the logs are not necessarily displayed! It seems like they are only displayed when the last test to be run with the fixture fails, triggering the printing of the logs.
I think this behaviour should be documented or solved in some way. @todofixthis what do you think? I stumbled over this issue while testing the behaviour in #28. Otherwise it is not related to that PR since this 'bug' has been there since introducing the dynamically scoped fixture.
The text was updated successfully, but these errors were encountered: