diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-04 16:02:47 -0700 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-04-04 16:02:47 -0700 |
commit | 49b98ad5a16ea8d6376cb66173d88b6d8cb2f822 (patch) | |
tree | a91e4fac2e2312d2f49b477a6a692c7d7596b2d7 | |
parent | 0b443ea261eba48271def0994a202bbf932a6787 (diff) | |
parent | df45572111dbce4a576d23648ef8b5b88e1df899 (diff) | |
download | psutil-49b98ad5a16ea8d6376cb66173d88b6d8cb2f822.tar.gz |
Merge branch 'master' of github.com:giampaolo/psutil
-rw-r--r-- | HISTORY.rst | 1 | ||||
-rw-r--r-- | Makefile | 5 | ||||
-rwxr-xr-x | psutil/tests/runner.py | 29 | ||||
-rwxr-xr-x | scripts/internal/winmake.py | 10 |
4 files changed, 43 insertions, 2 deletions
diff --git a/HISTORY.rst b/HISTORY.rst index b5e1e6a0..b01d8fea 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -10,6 +10,7 @@ the number of physical CPUs in case /proc/cpuinfo does not provide this info. - 1458_: provide coloured test output. Also show failures on KeyboardInterrupt. - 1464_: various docfixes (always point to python3 doc, fix links, etc.). +- 1478_: add make command to re-run tests failed on last run. **Bug fixes** @@ -49,6 +49,7 @@ clean: ## Remove all build files. *.egg-info \ *\$testfn* \ .coverage \ + .failed-tests.txt \ .tox \ build/ \ dist/ \ @@ -151,6 +152,10 @@ test-by-name: ## e.g. make test-by-name ARGS=psutil.tests.test_system.TestSyste ${MAKE} install @$(TEST_PREFIX) $(PYTHON) -m unittest -v $(ARGS) +test-failed: ## Re-run tests which failed on last run + ${MAKE} install + $(TEST_PREFIX) $(PYTHON) -c "import psutil.tests.runner as r; r.run(last_failed=True)" + test-coverage: ## Run test coverage. ${MAKE} install # Note: coverage options are controlled by .coveragerc file diff --git a/psutil/tests/runner.py b/psutil/tests/runner.py index 9e19d198..1a28aa43 100755 --- a/psutil/tests/runner.py +++ b/psutil/tests/runner.py @@ -24,11 +24,13 @@ except ImportError: import psutil from psutil._common import memoize +from psutil.tests import safe_rmpath from psutil.tests import TOX HERE = os.path.abspath(os.path.dirname(__file__)) VERBOSITY = 1 if TOX else 2 +FAILED_TESTS_FNAME = '.failed-tests.txt' if os.name == 'posix': GREEN = 1 RED = 2 @@ -157,15 +159,38 @@ def get_suite(name=None): return suite -def run(name=None): +def get_suite_from_failed(): + # ...from previously failed test run + suite = unittest.TestSuite() + if not os.path.isfile(FAILED_TESTS_FNAME): + return suite + with open(FAILED_TESTS_FNAME, 'rt') as f: + names = f.read().split() + for n in names: + suite.addTest(unittest.defaultTestLoader.loadTestsFromName(n)) + return suite + + +def save_failed_tests(result): + if result.wasSuccessful(): + return safe_rmpath(FAILED_TESTS_FNAME) + with open(FAILED_TESTS_FNAME, 'wt') as f: + for t in result.errors + result.failures: + tname = str(t[0]) + f.write(tname + '\n') + + +def run(name=None, last_failed=False): setup_tests() runner = ColouredRunner(verbosity=VERBOSITY) + suite = get_suite_from_failed() if last_failed else get_suite(name) try: - result = runner.run(get_suite(name)) + result = runner.run(suite) except (KeyboardInterrupt, SystemExit) as err: print("received %s" % err.__class__.__name__, file=sys.stderr) runner.result.printErrors() sys.exit(1) else: + save_failed_tests(result) success = result.wasSuccessful() sys.exit(0 if success else 1) diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py index cbdeebdc..75b4c348 100755 --- a/scripts/internal/winmake.py +++ b/scripts/internal/winmake.py @@ -318,6 +318,7 @@ def clean(): "*.~", "*__pycache__", ".coverage", + ".failed-tests.txt", ".tox", ) safe_rmtree("build") @@ -440,6 +441,15 @@ def test_by_name(): @cmd +def test_failed(): + """Re-run tests which failed on last run.""" + install() + test_setup() + sh('%s -c "import psutil.tests.runner as r; r.run(last_failed=True)"' % ( + PYTHON)) + + +@cmd def test_script(): """Quick way to test a script""" try: |