簡體   English   中英

Django完全忽略Asynch測試(Django頻道)

[英]Django Ignoring Asynch Tests Completely (Django Channels)

我正在開發運行Python3.6,Django 2.0和Channels 2.0.2的Web服務器。 我想構建一些測試來確保我的websocket消費者在表現自己,不幸的是,每當我運行測試時,他們都被完全忽略。

我一直在關注測試官方Channels文檔 ,並且我復制了Channels 用於測試其通用消費者的代碼,但是每當我運行測試時,測試運行器只是報告它沒有運行測試:

Creating test database for alias 'default'...
System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
Destroying test database for alias 'default'...

我沒有錯誤或其他警告。 我已經檢查過我已經安裝了pytest-asynciopytest-django ,並且我100%確定通過在頂部放置一個print語句來加載文件本身。 我所有的其他測試都正常運行。 任何幫助是極大的贊賞。

默認的Django測試運行器未實現與asyncio一起使用,並且無法正確自動發現用@pytest.mark.asyncio修飾的測試函數。

常見問題解答做了一個很好的工作,概述了測試不會找到的原因,但這就是我為了解決這個問題而做的事情。

安裝庫pytestpytest-djangopytest-asyncio

pipenv install pytest pytest-django pytest-asyncio

在項目的根目錄下創建一個文件pytest.ini ,其中包含以下內容並交換projectname.settings以獲取項目設置文件的正確名稱。

[pytest]
DJANGO_SETTINGS_MODULE = projectname.settings
python_files = tests.py test_*.py *_tests.py

然后,我可以使用pytest運行測試,如https://channels.readthedocs.io/en/latest/topics/testing.html中所述

如果這仍然不起作用,請給它一個外觀: https//pytest-django.readthedocs.io/en/latest/faq.html#faq-tests-not-being-picked-up

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM