Hi,

this question is related to Channels 2.0, Django 2.0, pytest 3.4, 
pytest-django 3.1 and pytest-asyncio 0.8.

I created a pytest:

@pytest.fixture
def db_with_obj(db):
    factories.MyModelFactory()

@pytest.mark.asyncio
async def test_something(db_with_obj):
    print(models.MyModelFactory.objects.all())
    obj = models.MyModelFactory.objects.first()
    communicator = WebsocketCommunicator(MyConsumer, 'ws/')
    connected, subprotocol = await communicator.connect()
    assert connected
    await communicator.send_to(text_data=json.dumps({
        'id': obj.pk,
        'content': 'my content',
    }))
    response = await communicator.receive_from()
    assert response == 'my content'
    await communicator.disconnect()

print gives me <QuerySet [<MyModel: 1>]>

Here my Consumer code:

class MyConsumer(WebsocketConsumer):
    def receive(self, text_data=None, bytes_data=None):
        print(models.MyModel.objects.all())
        # ...

print gives me <QuerySet []>

I don't know what I'm doing wrong. I didn't use both, pytest and Python 
async code, before. Therefore I don't know where to look for the solution, 
though I think it's easy to solve. Any hint appreciated.

Thanks :)

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/7e5f63f4-789c-413e-a8d2-fcf8ea62a2cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to