diff options
Diffstat (limited to 'psutil')
-rw-r--r-- | psutil/tests/README.rst | 25 | ||||
-rw-r--r-- | psutil/tests/__init__.py | 30 | ||||
-rwxr-xr-x | psutil/tests/__main__.py | 14 | ||||
-rwxr-xr-x | psutil/tests/runner.py | 37 |
4 files changed, 54 insertions, 52 deletions
diff --git a/psutil/tests/README.rst b/psutil/tests/README.rst index 2ad91c14..637fb7dd 100644 --- a/psutil/tests/README.rst +++ b/psutil/tests/README.rst @@ -1,19 +1,24 @@ Instructions for running tests ============================== -- The recommended way to run tests (also on Windows) is to cd into psutil root - directory and run ``make test``. +* There are two ways of running tests. If psutil is already installed: -- Depending on the Python version, dependencies for running tests include + python -m psutil.tests + + If you have a copy of the source code: + + make test + +* Depending on the Python version, dependencies for running tests include ``ipaddress``, ``mock`` and ``unittest2`` modules. - On Windows also ``pywin32`` and ``wmi`` modules are recommended - (although optional). - Run ``make setup-dev-env`` to install all deps (also on Windows). + On Windows you'll also need ``pywin32`` and ``wmi`` modules. + If you have a copy of the source code you can run ``make setup-dev-env`` to + install all deps (also on Windows). -- To run tests on all supported Python versions install tox +* To run tests on all supported Python versions install tox (``pip install tox``) then run ``tox`` from psutil root directory. -- Every time a commit is pushed tests are automatically run on Travis +* Every time a commit is pushed tests are automatically run on Travis (Linux, OSX) and appveyor (Windows): - - https://travis-ci.org/giampaolo/psutil/ - - https://ci.appveyor.com/project/giampaolo/psutil + * https://travis-ci.org/giampaolo/psutil/ + * https://ci.appveyor.com/project/giampaolo/psutil diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 05d2de2e..84eafe9e 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -127,6 +127,7 @@ TESTFN_UNICODE = TESTFN + u"-ƒőő" # --- paths +HERE = os.path.abspath(os.path.dirname(__file__)) ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) SCRIPTS_DIR = os.path.join(ROOT_DIR, 'scripts') @@ -560,11 +561,23 @@ class TestCase(unittest.TestCase): unittest.TestCase = TestCase -def retry_before_failing(retries=NO_RETRIES): - """Decorator which runs a test function and retries N times before - actually failing. - """ - return retry(exception=AssertionError, timeout=None, retries=retries) +def get_suite(): + testmodules = [os.path.splitext(x)[0] for x in os.listdir(HERE) + if x.endswith('.py') and x.startswith('test_') and not + x.startswith('test_memory_leaks')] + suite = unittest.TestSuite() + for tm in testmodules: + # ...so that the full test paths are printed on screen + tm = "psutil.tests.%s" % tm + suite.addTest(unittest.defaultTestLoader.loadTestsFromName(tm)) + return suite + + +def run_suite(): + """Run unit tests.""" + result = unittest.TextTestRunner(verbosity=VERBOSITY).run(get_suite()) + success = result.wasSuccessful() + sys.exit(0 if success else 1) def run_test_module_by_name(name): @@ -578,6 +591,13 @@ def run_test_module_by_name(name): sys.exit(0 if success else 1) +def retry_before_failing(retries=NO_RETRIES): + """Decorator which runs a test function and retries N times before + actually failing. + """ + return retry(exception=AssertionError, timeout=None, retries=retries) + + def skip_on_access_denied(only_if=None): """Decorator to Ignore AccessDenied exceptions.""" def decorator(fun): diff --git a/psutil/tests/__main__.py b/psutil/tests/__main__.py new file mode 100755 index 00000000..5f7bb528 --- /dev/null +++ b/psutil/tests/__main__.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Run unit tests. This is invoked by: + +$ python -m psutil.tests +""" + +from psutil.tests import run_suite +run_suite() diff --git a/psutil/tests/runner.py b/psutil/tests/runner.py deleted file mode 100755 index 88bcd620..00000000 --- a/psutil/tests/runner.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2007-2016 Giampaolo Rodola' <g.rodola@gmail.com>. -# Use of this source code is governed by MIT license that can be -# found in the LICENSE file. - -"""Script for running all test files (except memory leaks tests).""" - -import os -import sys - -from psutil.tests import unittest -from psutil.tests import VERBOSITY - - -def get_suite(): - HERE = os.path.abspath(os.path.dirname(__file__)) - testmodules = [os.path.splitext(x)[0] for x in os.listdir(HERE) - if x.endswith('.py') and x.startswith('test_') and not - x.startswith('test_memory_leaks')] - suite = unittest.TestSuite() - for tm in testmodules: - # ...so that "make test" will print the full test paths - tm = "psutil.tests.%s" % tm - suite.addTest(unittest.defaultTestLoader.loadTestsFromName(tm)) - return suite - - -def main(): - # run tests - result = unittest.TextTestRunner(verbosity=VERBOSITY).run(get_suite()) - success = result.wasSuccessful() - sys.exit(0 if success else 1) - - -if __name__ == '__main__': - main() |