Repository: celery/celery

Issue:
Getting error when  write a unit test using PyTest for a celery task -> pytest.PytestUnknownMarkWarning: Unknown pytest.mark.celery
I wrote the following bare minimum unit test class for celery

```python
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 am getting the following error when executing the test
```
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?
```

These are the items in the `_mark` set `structures.py` file 
```python
<class 'set'>: {
    'tryfirst', 
    'skip',
     'black',
     'filterwarnings',
     'parametrize',
     'usefixtures',
     'skipif',
     'xfail',
     'no_cover',
     'trylast'
}
```

These are the installed python libraries 
```
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

```
Is the documentation missing an additional package?


Discussion:
which version of pytest you are using?
@auvipy  pytest==5.1.1, I have listed all the libraries with exact versions
pytest 5.x versions only support python 3.x series so we are using 4.x series with pytest 4.6.x seris
pytest 5.x will be used with celery 5.x version onward which will be py3 only
Means it doesn't support python3.6 celery 4.0.x and pytest 5.0.x? @auvipy  If thats the case please update the documentation 
it only doesnt support pytest 5.x

Resolving patch:
diff --git a/celery/contrib/pytest.py b/celery/contrib/pytest.py
--- a/celery/contrib/pytest.py
+++ b/celery/contrib/pytest.py
@@ -15,6 +15,16 @@
 # Well, they're called fixtures....
 
 
+def pytest_configure(config):
+    """Register additional pytest configuration."""
+    # add the pytest.mark.celery() marker registration to the pytest.ini [markers] section
+    # this prevents pytest 4.5 and newer from issueing a warning about an unknown marker
+    # and shows helpful marker documentation when running pytest --markers.
+    config.addinivalue_line(
+        "markers", "celery(**overrides): override celery configuration for a test case"
+    )
+
+
 @contextmanager
 def _create_app(enable_logging=False,
                 use_trap=False,


Test patch:
diff --git a/t/unit/contrib/test_pytest.py b/t/unit/contrib/test_pytest.py
new file mode 100644
--- /dev/null
+++ b/t/unit/contrib/test_pytest.py
@@ -0,0 +1,34 @@
+import pytest
+
+try:
+    from pytest import PytestUnknownMarkWarning  # noqa: F401
+
+    pytest_marker_warnings = True
+except ImportError:
+    pytest_marker_warnings = False
+
+
+pytest_plugins = ["pytester"]
+
+
+@pytest.mark.skipif(
+    not pytest_marker_warnings,
+    reason="Older pytest version without marker warnings",
+)
+def test_pytest_celery_marker_registration(testdir):
+    """Verify that using the 'celery' marker does not result in a warning"""
+    testdir.plugins.append("celery")
+    testdir.makepyfile(
+        """
+        import pytest
+        @pytest.mark.celery(foo="bar")
+        def test_noop():
+            pass
+        """
+    )
+
+    result = testdir.runpytest('-q')
+    with pytest.raises(ValueError):
+        result.stdout.fnmatch_lines_random(
+            "*PytestUnknownMarkWarning: Unknown pytest.mark.celery*"
+        )