0

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?

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
user2954587
  • 4,661
  • 6
  • 43
  • 101

2 Answers2

0

You should pass the arguments as a list, not a string.

import subprocess
subprocess.call(["python",  "-m", "webapp.lib.cron.my_cron"])
Alasdair
  • 298,606
  • 55
  • 578
  • 516
0

use Popen because subprocess.Popen is more general than subprocess.call.

import subprocess
subprocess.Popen(["python",  "-m", "webapp.lib.cron.my_cron"])
Aayush Tiwari
  • 71
  • 1
  • 1
  • 3