Hello Django users,
This sounds like a pretty newbish question, but I am struggling on how to write tests for Django-channels 2 websocket consumers that access the database. I am not familiar with pytest and asynchronous programming (the bread and butter of Channels testing), so while I caught up with pytest, I am still a bit lost between `async` and `await`.
Using Django/Django-REST, when I test a view method which modifies a database object for a given request, here is what I usually do:
All of this synchronously. With Channels, I thought I could do the same for a consumer method which modifies a database object on a given event:
All of this asynchronously, as stated in the documentation,
but this is a synchronous test scenario! Obviously, it does not
work, as step 2. is executed with `await` and step 3. is achieved
before step 2. finishes. I tried to execute step 2. synchronously
using `async_to_sync` but it does not work (I can give details).
I am missing something, how can I test such a consumer method? Is
this possible? The documentation does not give any hint on this…
Help would be much appreciated!
Cheers,
-- Neraste
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c22c1afb-ff85-5af9-66f6-a94cdc77a545%40gmail.com.
For more options, visit https://groups.google.com/d/optout.