我为芹菜编写了以下裸机最低单元测试班
import pytest
@pytest.fixture
def celery_config():
return {
"broker_url": "redis://localhost:6379/0",
"result_backend": "redis://localhost:6379/0"
}
@pytest.mark.celery(result_backend="redis://")
class GetHash:
def test_some(self):
pass
我有celery version 4.3.0
和PyTest
及其插件,如下所示
pytest==5.1.1
pytest-black==0.3.7
pytest-cov==2.7.1
pytest-forked==1.0.2
pytest-runner==5.1
pytest-xdist==1.29.0
尝试测试时出现以下错误
test_get_hash.py:12: in <module>
@pytest.mark.celery(result_backend="redis://")
/home/work/.virtualenvs/dev_env/lib/python3.6/site-packages/_pytest/mark/structures.py:324: in __getattr__
PytestUnknownMarkWarning,
E pytest.PytestUnknownMarkWarning: Unknown pytest.mark.celery - is this a typo?
软件包列表
amqp==2.5.1
anyjson==0.3.3
apipkg==1.5
appdirs==1.4.3
atomicwrites==1.3.0
attrs==19.1.0
autoflake==1.3
Babel==2.7.0
bandit==1.6.2
billiard==3.6.1.0
black==19.3b0
celery==4.3.0
Cerberus==1.3.1
certifi==2019.6.16
chardet==3.0.4
checksumdir==1.1.6
Click==7.0
coverage==4.5.3
execnet==1.6.0
Flask==1.0.2
Flask-Cors==3.0.8
flower==0.9.3
gitdb2==2.0.5
GitPython==2.1.13
idna==2.8
importlib-metadata==0.19
isort==4.3.20
itsdangerous==1.1.0
Jinja2==2.10.1
kombu==4.6.4
MarkupSafe==1.1.1
mock==3.0.5
more-itertools==7.0.0
mysql-connector-python==8.0.16
Nuitka==0.6.5
packaging==19.1
pbr==5.4.2
pluggy==0.12.0
protobuf==3.7.1
py==1.8.0
pyflakes==2.1.1
pyparsing==2.4.2
pytest==5.1.1
pytest-black==0.3.7
pytest-cov==2.7.1
pytest-forked==1.0.2
pytest-runner==5.1
pytest-xdist==1.29.0
python-dateutil==2.8.0
python-dotenv==0.10.1
pytz==2019.2
PyYAML==5.1.2
redis==3.3.8
requests==2.22.0
rq==1.1.0
six==1.12.0
smmap2==2.0.5
SQLAlchemy==1.3.3
stevedore==1.30.1
toml==0.10.0
tornado==5.1.1
urllib3==1.25.3
vine==1.3.0
wcwidth==0.1.7
Werkzeug==0.15.2
我是否需要为此安装特殊的插件才能解决该错误?
答案 0 :(得分:3)
除非您enabled strict markers,否则您看到的是警告,而不是错误。您可以忽略它,或者告诉pytest不向您显示它们(使用jq 'del( .outer[]|select(.inner[0].value == "val1"))'
)或忽略此特定警告(使用--disable-warnings
)。
您也可以通过将其添加到-W ignore::pytest.PytestUnknownMarkWarning
文件中来register the marker:
pytest.ini
celery pytest插件将采用您使用标记做的任何一种特定于测试的配置。
这些警告为introduced in Pytest 4.5,理想情况下,Celery项目应在其插件代码中pre-register the marker。我有added this to your Celery issue report。
我还made a pull request使Celery添加注册。此后不久合并,因此upcoming Celery 4.4.0 release将使上述内容过时。