Skip to content
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

Chainlit context not found in unit tests for applications #1528

Open
dokato opened this issue Nov 18, 2024 · 1 comment
Open

Chainlit context not found in unit tests for applications #1528

dokato opened this issue Nov 18, 2024 · 1 comment
Labels
question Further information is requested unit-tests Has unit tests.

Comments

@dokato
Copy link

dokato commented Nov 18, 2024

Describe the bug
My unittests fails with:

chainlit.context.ChainlitContextException: Chainlit context not found

To Reproduce

I have a function that generates chainlit text:

def _generate_message_text(txt:str) ->cl.Text:
    return cl.Text(name="Message", content=f"message: {txt}", display="inline")

but any sort of unit test like here

def test_generate_message_text():
    cl_text = _generate_message_text("cat")
    assert 1==1

results in an error as above. What is recommended way to write unittests for functions that generate chainlit objects?

Expected behavior
An easy way to unit test chainlit generation elements outside of contex, or easy mechanism to mock the context.

chainlit ver.: 1.0.200

@dosubot dosubot bot added the unit-tests Has unit tests. label Nov 18, 2024
@dokterbob
Copy link
Collaborator

Hi @dokato, excellent question!

In our internal unit tests, we use a pytest fixture to create a ChainlitContext.

async def create_chainlit_context(mock_session):

I'd be very curious to learn whether and how you manage to use something similar to do testing of applications built with chainlit.

Lastly, I would strongly suggest you upgrade if you are offering a public-facing application. There's a lot of security issues in chainlit as well as the dependencies fixed in later releases.

@dokterbob dokterbob added question Further information is requested and removed needs-triage labels Nov 19, 2024
@dokterbob dokterbob changed the title What is advised way to write unittests for functions that generate chainlit objects? Chainlit context not found in unit tests for applications Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested unit-tests Has unit tests.
Projects
None yet
Development

No branches or pull requests

2 participants