I'm trying to run a script from a django unit test but failing to do so.
The script I want to call can be run from the command line with python -m webapp.lib.cron.my_cron
I've tried:
from subprocess import call
call("python -m webapp.lib.cron.my_cron")
and receive the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'python -m webapp.lib.cron.my_cron'
How can I run this script in a django unittest?
You should pass the arguments as a list, not a string.
import subprocess
subprocess.call(["python", "-m", "webapp.lib.cron.my_cron"])