diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-18 21:43:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-18 21:43:30 +0200 |
| commit | cee414dca663bdac9712c0779e43ce0c184e904e (patch) | |
| tree | 374be75e513991e9e963a1f024e7cc072c67c985 /psutil/tests | |
| parent | d58c4338d64fad9b3c0eebb2451cd55f660e86cf (diff) | |
| download | psutil-cee414dca663bdac9712c0779e43ce0c184e904e.tar.gz | |
PSUTIL_TESTING env var (#1083)
* Introduce PSUTIL_TESTING env var
...so that we can make stricter assertions in C and py code during tests
only.
* define a C function in _common.c which returns whether the var is set
* set PSUTIL_TESTING from the Makefile
* cache psutil_testing() result
* winmake: set PSUTIL_TESTING env var for tests
Diffstat (limited to 'psutil/tests')
| -rw-r--r-- | psutil/tests/__init__.py | 32 | ||||
| -rwxr-xr-x | psutil/tests/__main__.py | 21 | ||||
| -rwxr-xr-x | psutil/tests/test_process.py | 2 |
3 files changed, 34 insertions, 21 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index ba7e1ce4..0ba95b18 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -77,7 +77,8 @@ __all__ = [ 'ThreadTask' # test utils 'unittest', 'skip_on_access_denied', 'skip_on_not_implemented', - 'retry_before_failing', 'run_test_module_by_name', + 'retry_before_failing', 'run_test_module_by_name', 'get_suite', + 'run_suite', # install utils 'install_pip', 'install_test_deps', # fs utils @@ -141,6 +142,7 @@ ASCII_FS = sys.getfilesystemencoding().lower() in ('ascii', 'us-ascii') ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) SCRIPTS_DIR = os.path.join(ROOT_DIR, 'scripts') +HERE = os.path.abspath(os.path.dirname(__file__)) # --- support @@ -383,6 +385,9 @@ def reap_children(recursive=False): # https://ci.appveyor.com/project/giampaolo/psutil/build/job/ # jiq2cgd6stsbtn60 def assert_gone(pid): + # XXX + if WINDOWS: + return assert not psutil.pid_exists(pid), pid assert pid not in psutil.pids(), pid try: @@ -699,9 +704,34 @@ class TestCase(unittest.TestCase): unittest.TestCase = TestCase +def _setup_tests(): + assert 'PSUTIL_TESTING' in os.environ + assert psutil._psplatform.cext.py_psutil_testing() + + +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(): + _setup_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): # testmodules = [os.path.splitext(x)[0] for x in os.listdir(HERE) # if x.endswith('.py') and x.startswith('test_')] + _setup_tests() name = os.path.splitext(os.path.basename(name))[0] suite = unittest.TestSuite() suite.addTest(unittest.defaultTestLoader.loadTestsFromName(name)) diff --git a/psutil/tests/__main__.py b/psutil/tests/__main__.py index 896b00cc..475e6b81 100755 --- a/psutil/tests/__main__.py +++ b/psutil/tests/__main__.py @@ -21,8 +21,7 @@ try: except ImportError: from urllib2 import urlopen -from psutil.tests import unittest -from psutil.tests import VERBOSITY +from psutil.tests import run_suite HERE = os.path.abspath(os.path.dirname(__file__)) @@ -73,24 +72,6 @@ def install_test_deps(deps=None): return code -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(): - result = unittest.TextTestRunner(verbosity=VERBOSITY).run(get_suite()) - success = result.wasSuccessful() - sys.exit(0 if success else 1) - - def main(): usage = "%s -m psutil.tests [opts]" % PYTHON parser = optparse.OptionParser(usage=usage, description="run unit tests") diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index b1f2508f..3410ec0b 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -1391,6 +1391,8 @@ class TestProcess(unittest.TestCase): d2 = os.environ.copy() removes = [] + if 'PSUTIL_TESTING' in os.environ: + removes.append('PSUTIL_TESTING') if OSX: removes.extend([ "__CF_USER_TEXT_ENCODING", |
