Closed xhujerr closed 1 month ago
Will this work?
from unittest_parallel.main import main as unittest_parallel_main
unittest_parallel_main(['-s', parser.TestDirectory])
Yes, I'm able to run the tests as you suggest. Thank you.
result = unittest_parallel_main(['-s', parser.TestDirectory, "--level", "class"])
But that opens new questions (I can open a new issue if you prefer):
No need to open a new issue.
You can wrap your main call with a try-except to catch the SystemExit exception and get the status code. Capturing output is an issue due to multiprocessing though.
A better approach might be to use subprocess:
import subprocess
run_args = ['unittest-parallel', '-s', parser.TestDirectory, '--level', 'class']
result = subprocess.run(run_args, stdout=subprocess.PIPE, text=True, stderr=subprocess.STDOUT)
if result.returncode:
print(f'ERROR (code {result.returncode}):')
print(result.stdout)
else:
print('OK')
Does that work?
As for splitting up classes I'd recommend running unittest-parallel with different "-k" arguments (e.g. -k TestClass1, -k TestClass2) to find which classes run-long. I'd also recommend trying --level test if your tests are long-running.
@xhujerr, curious to know if any of that worked for you. If no, were you able to find a solution for your needs?
Closing due to inactivity
Currently I use unittest from a python module something like:
To use parallelization I'd probably need to cherry pick snippets of code from your main function (separated by comments like f.e. # Run the tests in parallel). Would you mind splitting your main function so that I can import those parts easily?