Flask application with Celery using Test-Driven Development (TDD):
/myapp
/job_queue
__init__.py
/src
/main
__init__.py
app.py
celery_config.py
/tasks
__init__.py
mytasks.py
/tests
__init__.py
/unit
__init__.py
test_app.py
test_tasks.py
/integration
__init__.py
test_app_integration.py
run.py
run_celery.py
requirements.txt
Here's what each file/directory is for:
/myapp
: The outer myapp directory is the root of your project./myapp/job_queue
: This is the actual Python module of your application./myapp/job_queue/src
: This directory holds your source code./myapp/job_queue/src/main
: This directory includes the main Flask application and Celery configuration./myapp/job_queue/src/tasks
: This directory includes the Celery tasks./myapp/job_queue/tests
: This directory includes all the test cases./myapp/job_queue/tests/unit
: This directory includes all the unit tests./myapp/job_queue/tests/integration
: This directory includes all the integration tests.run.py
: This script runs your application.run_celery.py
: This script runs your Celery worker.requirements.txt
: This file lists all of the Python packages that your app depends on.
You could run your tests using a library like pytest
with the following command:
pytest myapp/tests
This structure separates the main application and tasks from the test suite, providing a clean organization for a TDD project.