Skip to content

[WIP] Remove subprocess usage from discovery #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stestr/subunit_runner/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def list(self, test, loader=None):
result.status(file_name="import errors", runnable=False,
file_bytes=failed_descr,
mime_type="text/plain;charset=utf8")
sys.exit(2)
raise Exception("listing test %s errored" % test)

def _list(self, test):
test_ids, errors = program.list_test(test)
Expand Down
22 changes: 14 additions & 8 deletions stestr/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from functools import partial
import io
import os
import re
Expand All @@ -24,6 +25,8 @@
from stestr import results
from stestr import scheduler
from stestr import selection
from stestr.subunit_runner import program as sub_prog
from stestr.subunit_runner import run as sub_run
from stestr import testlist


Expand Down Expand Up @@ -213,27 +216,30 @@ def list_tests(self):

:return: A list of test ids.
"""
run_proc = self._start_process(self.list_cmd)
out, err = run_proc.communicate()
if run_proc.returncode != 0:
discovery_buffer = io.BytesIO()
runner = sub_run.SubunitTestRunner
list_cmd = [x.strip('"') for x in self.list_cmd.split(' ')[2:-1] if x]
try:
sub_prog.TestProgram(module=None, argv=list_cmd,
testRunner=partial(runner,
stdout=discovery_buffer))
except Exception:
sys.stdout.write("\n=========================\n"
"Failures during discovery"
"\n=========================\n")
new_out = io.BytesIO()
v2.ByteStreamToStreamResult(
io.BytesIO(out), 'stdout').run(
results.CatFiles(new_out))
discovery_buffer, 'stdout').run(results.CatFiles(new_out))
out = new_out.getvalue()
if out:
sys.stdout.write(out.decode('utf8'))
if err:
sys.stderr.write(err.decode('utf8'))
sys.stdout.write("\n" + "=" * 80 + "\n"
"The above traceback was encountered during "
"test discovery which imports all the found test"
" modules in the specified test_path.\n")
exit(100)
ids = testlist.parse_enumeration(out)
ids = testlist.parse_enumeration(discovery_buffer.getvalue())
discovery_buffer.close()
return ids

def run_tests(self):
Expand Down