summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-04-25 02:33:05 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2020-04-25 02:33:05 +0200
commitf025b5cd92d04dc82c5111102197c4e69e4808d6 (patch)
treea48923dfd7425b7f86df964abfe5cea7610341cb
parent4c325b347ade497451736bc66c0e7df47d9bdb7f (diff)
downloadpsutil-f025b5cd92d04dc82c5111102197c4e69e4808d6.tar.gz
refact
-rwxr-xr-xpsutil/tests/runner.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/psutil/tests/runner.py b/psutil/tests/runner.py
index 2919fbf8..dd8a3caa 100755
--- a/psutil/tests/runner.py
+++ b/psutil/tests/runner.py
@@ -26,6 +26,11 @@ try:
except ImportError:
ctypes = None
+try:
+ import concurrencytest # pip install concurrencytest
+except ImportError:
+ concurrencytest = None
+
import psutil
from psutil._common import hilite
from psutil._common import print_color
@@ -209,10 +214,9 @@ class Runner:
def run_parallel(self):
"""Run tests in parallel."""
- from concurrencytest import ConcurrentTestSuite, fork_for_tests
-
ser_suite, par_suite = self.loader.parallel()
- par_suite = ConcurrentTestSuite(par_suite, fork_for_tests(NWORKERS))
+ par_suite = concurrencytest.ConcurrentTestSuite(
+ par_suite, concurrencytest.fork_for_tests(NWORKERS))
# run parallel
print("starting parallel tests using %s workers" % NWORKERS)
@@ -278,13 +282,21 @@ def main():
if not opts.last_failed:
safe_rmpath(FAILED_TESTS_FNAME)
- if opts.parallel and not opts.last_failed:
- runner.run_parallel()
+
+ if opts.last_failed:
+ runner.run_last_failed()
+ elif not opts.parallel:
+ runner.run()
+ # parallel
+ elif concurrencytest is None:
+ print_color("concurrencytest module is not installed; "
+ "running serial tests instead", "red")
+ runner.run()
+ elif NWORKERS == 1:
+ print_color("only 1 CPU; running serial tests instead", "red")
+ runner.run()
else:
- if opts.last_failed:
- runner.run_last_failed()
- else:
- runner.run()
+ runner.run_parallel()
if __name__ == '__main__':