Skip to content

Commit

Permalink
add pylint to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Apr 8, 2022
1 parent 002213b commit e4c089a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion flask_celeryext/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def map_key(key):
return {map_key(key): value for key, value in config.items()}


def setup_task_logger(logger=None, **kwargs):
def setup_task_logger(logger=None, **kwargs): # pylint: disable=unused-argument
"""Make celery.task logger propagate exceptions.
Ensures that handlers in the RootLogger such as Sentry will be run.
Expand Down
2 changes: 1 addition & 1 deletion flask_celeryext/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .app import create_celery_app as pkg_create_celery_app


class FlaskCeleryExt(object):
class FlaskCeleryExt:
"""Flask-Celery extension."""

def __init__(self, app=None, create_celery_app=None):
Expand Down
9 changes: 8 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tests =
pytest-isort>=3.0.0
pytest-mock>=2.0.0
pytest-black>=0.3.12
pytest-pylint>=0.18.0
pytest-pydocstyle>=2.2.0
pytest>=6,<7
redis>=4.1.4
Expand All @@ -59,11 +60,17 @@ universal = 1
[pydocstyle]
add_ignore = D401,D403

[pylint]
max-line-length = 88

[pylint.messages_control]
disable = too-few-public-methods, abstract-method

[tool:isort]
profile=black

[tool:pytest]
addopts = --isort --black --pydocstyle --doctest-glob="*.rst" --doctest-modules --cov=flask_celeryext --cov-report=term-missing
addopts = --isort --black --pylint --pydocstyle --doctest-glob="*.rst" --doctest-modules --cov=flask_celeryext --cov-report=term-missing
testpaths = tests flask_celeryext
norecursedirs = .* *.egg *.egg-info env* artwork docs
filterwarnings = ignore::pytest.PytestDeprecationWarning
35 changes: 18 additions & 17 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from flask_celeryext.app import map_invenio_to_celery


class celery_conf:
class CeleryConf:
"""Configuration for testing Celery tasks for Celery >= 5.1.0."""

CELERY_TASK_ALWAYS_EAGER = True
Expand Down Expand Up @@ -56,8 +56,8 @@ def test_mapping():
def test_factory():
"""Test of factory method."""
# Set the current Celery application
c = Celery("mycurrent")
c.set_current()
celery_local = Celery("mycurrent")
celery_local.set_current()

app = Flask("testapp")
celery = create_celery_app(app)
Expand All @@ -68,26 +68,26 @@ def test_factory():
def test_appctx_task():
"""Test execution of Celery task with application context."""
app = Flask("testapp")
app.config.from_object(celery_conf)
app.config.from_object(CeleryConf)

# Set the current Celery application
c = Celery("mycurrent")
c.set_current()
celery_local = Celery("mycurrent")
celery_local.set_current()

celery = create_celery_app(app)

@celery.task
def appctx():
return current_app.name

r = appctx.delay()
assert r.result == "testapp"
result = appctx.delay()
assert result.result == "testapp"


def test_reqctx_task():
"""Test execution of Celery task with request context."""
app = Flask("testapp")
app.config.from_object(celery_conf)
app.config.from_object(CeleryConf)
celery = create_celery_app(app)

@celery.task(base=RequestContextTask)
Expand All @@ -98,16 +98,16 @@ def reqctx():
def reqctx2():
return request.method

r = reqctx.delay()
assert r.result == "GET"
result = reqctx.delay()
assert result.result == "GET"

assert pytest.raises(RuntimeError, reqctx2.delay)


def test_task_logger_propagation():
"""Test log propagation of Celery task."""
app = Flask("testapp")
app.config.from_object(celery_conf)
app.config.from_object(CeleryConf)
celery = create_celery_app(app)
celery.log.setup_task_loggers()

Expand All @@ -122,11 +122,12 @@ def logtask():


def test_subtask_and_eager_dont_create_new_app_context(mocker):
"""Test subtask and eager dont create new app context."""
app = Flask("testapp")
app.config.from_object(celery_conf)
app.config.from_object(CeleryConf)
# Set the current Celery application
c = Celery("mycurrent")
c.set_current()
celery_local = Celery("mycurrent")
celery_local.set_current()

celery = create_celery_app(app)

Expand All @@ -141,6 +142,6 @@ def maintask():
future = subtask.delay()
return future.result

r = maintask.delay()
assert r.result == "testapp"
result = maintask.delay()
assert result.result == "testapp"
assert spy.call_count == 1

0 comments on commit e4c089a

Please sign in to comment.