2👍
You need to redirect stderr to stdout. Here is the fixed code:
args_list = ['python', '/path/to/manage.py', 'test', 'myapp']
process=subprocess.Popen(args_list, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
output, errors = process.communicate()
print output
Alternatively in the shell, you can type something like this:
python manage.py test myapp > stdout.txt 2> stderr.txt
1👍
You can process test results with the unittest.TestResult object. See https://stackoverflow.com/a/284192/579461 for an example.
1👍
If you truly want to redirect stdout to a variable for examination, then you can do it using the following code:
from cStringIO import StringIO
import sys
output = StringIO()
sys.stdout = output
print "Hello World!"
print 42
sys.stdout = sys.__stdout__
print output.getvalue()
>>>
Hello World!
42
- [Django]-Django rest framework an always sorting field
- [Django]-Django-rest-framework API test 403 {'detail': 'You do not have permission to perform this action.'}
- [Django]-Django Rest framework how to create Family and assign members to that family while assigning roles to each member
- [Django]-Property decorator eager load and eager load in general using Django
0👍
How can all of the output be stores to a variable.
Redirect stderr to stdout:
from subprocess import check_output, STDOUT
output = check_output(args_list, stderr=STDOUT)
print output,
👤jfs
- [Django]-With django-filter, is there a quick way to support all possible lookups for fields?
- [Django]-"bar" in a Django template expression is a literal?
Source:stackexchange.com