Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc pytest plugin #6289

Merged
merged 4 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,14 @@ To run the Celery test suite you need to install
$ pip install -U -r requirements/default.txt

After installing the dependencies required, you can now execute
the test suite by calling :pypi:`py.test <pytest>`:
the test suite by calling :pypi:`pytest <pytest>`:

.. code-block:: console

$ py.test t/unit
$ py.test t/integration
$ pytest t/unit
$ pytest t/integration

Some useful options to :command:`py.test` are:
Some useful options to :command:`pytest` are:

* ``-x``

Expand All @@ -618,7 +618,7 @@ you can do so like this:

.. code-block:: console

$ py.test t/unit/worker/test_worker.py
$ pytest t/unit/worker/test_worker.py

.. _contributing-coverage:

Expand All @@ -636,11 +636,11 @@ Installing the :pypi:`pytest-cov` module:
Code coverage in HTML format
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#. Run :command:`py.test` with the ``--cov-report=html`` argument enabled:
#. Run :command:`pytest` with the ``--cov-report=html`` argument enabled:

.. code-block:: console

$ py.test --cov=celery --cov-report=html
$ pytest --cov=celery --cov-report=html

#. The coverage output will then be located in the :file:`htmlcov/` directory:

Expand All @@ -651,11 +651,11 @@ Code coverage in HTML format
Code coverage in XML (Cobertura-style)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#. Run :command:`py.test` with the ``--cov-report=xml`` argument enabled:
#. Run :command:`pytest` with the ``--cov-report=xml`` argument enabled:

.. code-block:: console

$ py.test --cov=celery --cov-report=xml
$ pytest --cov=celery --cov-report=xml

#. The coverage XML output will then be located in the :file:`coverage.xml` file.

Expand Down Expand Up @@ -828,7 +828,7 @@ make it easier for the maintainers to accept your proposed changes:
``Needs Test Coverage``.

- [ ] Make sure unit test coverage does not decrease.
``py.test -xv --cov=celery --cov-report=xml --cov-report term``.
``pytest -xv --cov=celery --cov-report=xml --cov-report term``.
You can check the current test coverage here: https://codecov.io/gh/celery/celery

- [ ] Run ``flake8`` against the code. The following commands are valid
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROJ=celery
PGPIDENT="Celery Security Team"
PYTHON=python
PYTEST=py.test
PYTEST=pytest
GIT=git
TOX=tox
ICONV=iconv
Expand Down
2 changes: 1 addition & 1 deletion celery/contrib/pytest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Fixtures and testing utilities for :pypi:`py.test <pytest>`."""
"""Fixtures and testing utilities for :pypi:`pytest <pytest>`."""
import os
from contextlib import contextmanager

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ WORKDIR $HOME/celery

# Setup the entrypoint, this ensures pyenv is initialized when a container is started
# and that any compiled files from earlier steps or from mounts are removed to avoid
# py.test failing with an ImportMismatchError
# pytest failing with an ImportMismatchError
ENTRYPOINT ["/entrypoint"]
15 changes: 12 additions & 3 deletions docs/userguide/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,23 @@ in this example:
with raises(Retry):
send_order(product.pk, 3, Decimal(30.6))

Py.test
=======
pytest
======

.. versionadded:: 4.0

Celery is also a :pypi:`pytest` plugin that adds fixtures that you can
Celery also makes a :pypi:`pytest` plugin available that adds fixtures that you can
use in your integration (or unit) test suites.

Enabling
--------

Celery initially ships the plugin in a disabled state, to enable it you can either:

* `pip install celery[pytest]`
* `pip install pytest-celery`
* or add `pytest_plugins = 'celery.contrib.pytest'` to your pytest.ini


Marks
-----
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def long_description():


class pytest(setuptools.command.test.test):
user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]
user_options = [('pytest-args=', 'a', 'Arguments to pass to pytest')]

def initialize_options(self):
setuptools.command.test.test.initialize_options(self)
Expand Down
2 changes: 1 addition & 1 deletion t/unit/app/test_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def seconds_almost_equal(self, a, b, precision):
try:
assertions.assertAlmostEqual(a, b + skew, precision)
except Exception as exc:
# AssertionError != builtins.AssertionError in py.test
# AssertionError != builtins.AssertionError in pytest
if 'AssertionError' in str(exc):
if index + 1 >= 3:
raise
Expand Down