Skip to content
Advertisement

How to return a non-zero exit code on a custom Django command while being able to test it?

I have a Django custom command that can return non-zero exit codes. I’d like to test this command, but the call to sys.exit(1) exits the test runner.

Is there a “proper” way to assign the exit code in a custom Django command?

My code currently looks like this:

JavaScript

Advertisement

Answer

I chose to mock the call to sys.exit() in the tests to prevent it to exit the test runner:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement