faust-streaming / faust

Python Stream Processing. A Faust fork
https://faust-streaming.github.io/faust/
Other
1.6k stars 180 forks source link

What is test_context? #555

Closed Zesky665 closed 11 months ago

Zesky665 commented 11 months ago

Problem

I used the code present in the tutorial for testing. The one available here: https://faust-streaming.github.io/faust/userguide/testing.html

When I ran this code, I got an error regarding the test_context() method.

UnboundLocalError: cannot access local variable 'order' where it is not associated with a value

Is there some other code which enables this test_context()? I tried googling it but it isn't turning up any useful results.

In case it's relevant I'm using the following versions: python = "^3.11" faust-streaming = "^0.10.16"

Thanks in advance 👍

dada-engineer commented 11 months ago

The test_context() provides a test agent to put data into the agent without the need for kafka within tests.

According to your error it seems like you have split the code blocks in the user guide into separate fields. The agent in the tutorial is called order and is defined on module level. The test function defined afterwards can therefor access it as a local variable (the error that is thrown)

Is this explanation enough? Do you have any more questions regarding this?

Zesky665 commented 11 months ago

Yes, thank you. I managed to figure it out eventually.