4

I wrote the following bare minimum unit test class for celery

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

I have the celery version 4.3.0 and PyTest and its plugins as follows

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

When trying to the test I am getting the following error

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?

List of packages

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

Do I need to install a special plugin for this in order to fix the error?

not 0x12
  • 19,360
  • 22
  • 67
  • 133

1 Answers1

4

What you are seeing is a warning, not an error, unless you enabled strict markers. You could just ignore this, or tell pytest to not show them to you (with --disable-warnings) or to ignore this specific warning (with -W ignore::pytest.PytestUnknownMarkWarning).

You can also register the marker, by adding it to your pytest.ini file:

[pytest]
markers =
    celery(**overrides): override celery configuration for a test case

The celery pytest plugin will pick up the test-specific configuration you made with the mark either way.

These warnings were introduced in Pytest 4.5, and ideally the Celery project should pre-register the marker in their plugin code. I've added this to your Celery issue report.

I've also made a pull request that makes Celery add the registration. This was merged not long afterwards, so the upcoming Celery 4.4.0 release will make the above obsolete.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343