`add_tasks_from` modifying the application?
See original GitHub issueHi @ewjoachim,
In our test environment, we use pytest
and are trying to monkeypatch our async procrastinate application as follows:
@pytest.fixture
async def patch_async_app(monkeypatch: pytest.MonkeyPatch):
original_app = main.procrastinate_app
with monkeypatch.context() as mp:
in_memory_async_app = App(connector=InMemoryConnector())
in_memory_async_app.add_tasks_from(original_app, namespace="original")
mp.setattr(main, "procrastinate_app", in_memory_async_app)
yield in_memory_async_app
in_memory_async_app.connector.reset()
The first test that uses this fixture passes just fine with these log entries:
[cloud-app] INFO:procrastinate.jobs:job_defer app.gql_mutations.defer_create_namespace_in_k8s[5]({'namespace': 'tenant-test-org1-b78d-test'})
[cloud-app-worker-k8s] INFO:procrastinate.worker.k8s-worker:start_job app.gql_mutations.defer_create_namespace_in_k8s[5]({'namespace': 'tenant-test-org1-b78d-test'})
(Note that we only recently started using the InMemoryConnector
in tests so we have some fixtures/test code that relies on actually enqueuing a task that is then picked up by a procrastinate worker, so in effect we have both in-memory and the “normal” task pipelines when we run these tests.)
However, the next test (using the exact same fixtures) then fails with the following logs:
[cloud-app] INFO:procrastinate.jobs:job_defer original:app.gql_mutations.defer_create_namespace_in_k8s[3]({'namespace': 'tenant-test-org2-c40f-test'})
Interestingly/strangely, the app name is now namespaced original:app
, which I can only assume is coming from our add_tasks_from
usage above since we pass namespace="original"
there and only there.
Is it possible that add_tasks_from
is doing some kind of mutation of the app
object, or am I just doing something stupid that I can’t yet see?
Thanks for your time! 😅
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
Top GitHub Comments
You may want to undo that after the yield, otherwise you’ll end up keeping a reference to the in memory app forever in your tests.
Hey @mecampbellsoup ! Thanks for taking the time to make a detailed ticket !
I could be wrong, but I believe that rather than
add_tasks_from
which is a method that’s been introduced for blueprints (so making re-usable groups of tasks), what you’re looking for iswith_connector
which I think is closer from what you’re trying to do.Let me know if changing this is enough for your usecase. Also, if it works, and if you have opinions on what should be changed in the docs to make this more obvious for the next people, please either point it or do a PR 😃