Robpol86/Flask-Large-Application-Example — pull request #2 by Robpol86 (2014-08-24 06:32:54+00:00)
Title: Increased test coverage. Fix Celery NotRegistered in tests.

Executing docopt in manage.py only if __name__ == '__main__'.
Mocking xmlrpclib instead of pypi.query (which was merged into update_package_list).
Moving alter_xmlrpc fixture to root conftest.py since it is used in ./tasks and ./views.
100% test coverage for all views.

Instead of creating Flask app in a pytest fixture, it will be done in the main body of the root conftest.py module.
pytest imports everything during test discovery, and then executes the autouse=True fixtures. This is a problem because one of the tests obviously imports Celery tasks, and upon import those tasks get registered by the @celery.task() decorator. Since the Flask app hasn't been created yet, celery.init_app() hasn't been called, so tasks are registered to an uninitialized Celery.
Now when pytest calls the fixture and create_app() is called, initializing Celery, those already-imported tasks don't get reregistered, so Celery raises NotRegistered exceptions once those task's .delay() methods are called.
Having create_app() in the body of the root conftest.py module guarantees the Flask app will be created before pytest imports those Celery tasks, so celery.init_app() is called before those celery.task() decorators try registering tasks.