Use python APIs to call run modules in ostestr
This commit switches from using subprocess to call testtools.run and subunit.run with python -m to directly calling the methods being run. This should make the non-default cases when using subunit.run and testtools.run faster, and it simplifies the code. As part of this, the code around call_subunit is fixed to make sure the it works as expected given different argument combinations. ostestr will still call subprocess to run testr, because the interface is more complex, and when subunit.run is used with subunit-trace, because the stdin handling is tricky. The subunit.run with subunit-trace case will be handled in a later patch.
This commit is contained in:
parent
8448bd574e
commit
6e1bb16cab
@ -13,11 +13,14 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import argparse
|
||||||
import copy
|
import copy
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
import argparse
|
from subunit import run as subunit_run
|
||||||
|
from testtools import run as testtools_run
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
@ -108,28 +111,24 @@ def call_testr(regex, subunit, pretty, list_tests, slowest, parallel, concur):
|
|||||||
return return_code
|
return return_code
|
||||||
|
|
||||||
|
|
||||||
def call_subunit_run(test_id, pretty):
|
def call_subunit_run(test_id, pretty, subunit):
|
||||||
cmd = ['python', '-m', 'subunit.run', test_id]
|
|
||||||
env = copy.deepcopy(os.environ)
|
|
||||||
if pretty:
|
if pretty:
|
||||||
|
env = copy.deepcopy(os.environ)
|
||||||
|
cmd = ['python', '-m', 'subunit.run', test_id]
|
||||||
ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
|
ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE)
|
||||||
proc = subprocess.Popen(['subunit-trace', '--no-failure-debug', '-f'],
|
proc = subprocess.Popen(['subunit-trace', '--no-failure-debug', '-f'],
|
||||||
env=env, stdin=ps.stdout)
|
env=env, stdin=ps.stdout)
|
||||||
ps.stdout.close()
|
ps.stdout.close()
|
||||||
else:
|
|
||||||
proc = subprocess.Popen(cmd, env=env)
|
|
||||||
proc.communicate()
|
proc.communicate()
|
||||||
return_code = proc.returncode
|
return proc.returncode
|
||||||
return return_code
|
elif subunit:
|
||||||
|
subunit_run.main([sys.argv[0], test_id], sys.stdout)
|
||||||
|
else:
|
||||||
|
testtools_run.main([sys.argv[0], test_id], sys.stdout)
|
||||||
|
|
||||||
|
|
||||||
def call_testtools_run(test_id):
|
def call_testtools_run(test_id):
|
||||||
cmd = ['python', '-m', 'testtools.run', test_id]
|
testtools_run.main([sys.argv[0], test_id], sys.stdout)
|
||||||
env = copy.deepcopy(os.environ)
|
|
||||||
proc = subprocess.Popen(cmd, env=env)
|
|
||||||
proc.communicate()
|
|
||||||
return_code = proc.returncode
|
|
||||||
return return_code
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -157,7 +156,7 @@ def main():
|
|||||||
elif opts.pdb:
|
elif opts.pdb:
|
||||||
exit(call_testtools_run(opts.pdb))
|
exit(call_testtools_run(opts.pdb))
|
||||||
else:
|
else:
|
||||||
exit(call_subunit_run(opts.no_discover, opts.pretty))
|
exit(call_subunit_run(opts.no_discover, opts.pretty, opts.subunit))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user