# Testing a non-terminating management command

**URL:** <https://forum.djangoproject.com/t/testing-a-non-terminating-management-command/33065>\
**Category:** Getting Started\
**Created:** [July 18, 2024, 3:16am UTC](https://forum.djangoproject.com/t/testing-a-non-terminating-management-command/33065 "2024-07-18T03:16:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SullivanChrisJ](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sullivanchrisj/32/21452_2.png) [@SullivanChrisJ](https://forum.djangoproject.com/u/SullivanChrisJ)\
**Post date:** [July 18, 2024, 3:16am UTC](https://forum.djangoproject.com/t/testing-a-non-terminating-management-command/33065/1 "2024-07-18T03:16:05Z")

</div>

Whether there is something other than a management command to do this job, I don’t know.

I need to integrate an MQTT subscriber application which I wrote in Python into a Django project. That is I want to use models instead of using psycopg2 directly. The only way I know how to do this is with a management command, which is not difficult to put together, but trying to write tests is stumping me right now because the management command never terminates, except abnormally, as it would run as (or similar to) a daemon.

But I was thinking about how to use TestCase with it, and it seems I would have to run it as a subprocess or something, with some kind of synchronization so I could assert things here and there.

I’m familiar with unit tests with TestCase and functional tests with Selenium and LiveServerTestCase but haven’t found much along these lines.

I’m just looking for suggestions about where to look.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![jacobtylerwalls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jacobtylerwalls/32/30603_2.png) [@jacobtylerwalls](https://forum.djangoproject.com/u/jacobtylerwalls)\
**Post date:** [July 18, 2024, 4:55pm UTC](https://forum.djangoproject.com/t/testing-a-non-terminating-management-command/33065/2 "2024-07-18T16:55:47Z")

</div>

I would consider just unit testing the smaller functions that make up your command. There’s not a need to test Django’s argument-parsing and result-reporting aspects. You could still add one integration test to sanity-check the daemon-launching/running behavior, and just patch it to exit in some way.
