Hello ! I have behavorial tests implemented follow...
# ask-for-help
l
Hello ! I have behavorial tests implemented following the doc: https://docs.bentoml.com/en/latest/guides/testing.html#http-behavior-tests But this raise an exception when trying to create an asgi app for my ASGITransport with bentoml 1.3.0 and 1.3.1 using:
Copy code
transport=httpx.ASGITransport(app=Summarization.to_asgi(init=True))
it raises an exception:
Copy code
TypeError: Service.to_asgi() got an unexpected keyword argument 'init'
Everything works as expected in 1.2.20 Is there anyone here who could help me fix this please ?
j
we are fixing this atm
🙏 1
thanks for reporting!
We have updated the docs. I think you should not need the
init
argument anymore
l
Tested using version 1.3.2: I just tried it. I can create a test client following your updated docs, thank you ! But calling my route only returns 500 errors 😕
j
could you share the error stack trace
l
I mean, calling my API returns HTTP 500 errors, the response being:
Copy code
{
  "error": "An unexpected error has occurred, please check the server log."
}
I have no stacktrace from my app, which runs with no error when i launch it using the containerized version with bentoml versions 1.2.20, 1.3.0, 1.3.1 and 1.3.2
j
Does it show any error when you do
bentoml serve
? maybe share us a reproducible example?
l
bentoml serve works perfectly, the only error that i can provide is the one i provided above. I believe the method defining my route is never reached using the test client
j
could you share me a reproducible code for your case, i.e. your service.py, and how you are calling your service. so that I can reproduce and examine the issue!
l
Here is an example, it comes from bentoml's documentation and doesn't work. bentoml serve works as expected but using the test client returns an error 500.
Copy code
from __future__ import annotations
import bentoml
from transformers import pipeline


EXAMPLE_INPUT = "anything to test"
@bentoml.service(
    resources={"cpu": "2"},
    traffic={"timeout": 10},
)
class Summarization:
    def __init__(self) -> None:
        # Load model into pipeline
        self.pipeline = pipeline('summarization')

    @bentoml.api
    def summarize(self, text: str) -> str:
        result = self.pipeline(text)
        return result[0]['summary_text']
Copy code
from starlette.testclient import TestClient

from service import Summarization, EXAMPLE_INPUT  # Imported from the Summarization service.py file


def test_request():
    # Initialize the ASGI app with the Summarization Service
    app = Summarization.to_asgi()
    # Create a test client to interact with the ASGI app
    test_client = TestClient(app=app)

    response = test_client.post("/summarize", json={"text": EXAMPLE_INPUT})
    # Retrieve the text from the response for validation
    summarized_text = response.text
    # Assert that the HTTP response status code is 200, indicating success
    assert response.status_code == 200
    # Assert that the summarized text is not empty
    assert summarized_text, "The summary should not be empty"