diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-05-17 19:05:00 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-05-17 19:05:00 +0200 |
commit | a6f03b9957d1be83f2c5cbe8099d7818ba581d89 (patch) | |
tree | 10fb972a0467e79aeadcdb535ae3578cbec224c0 | |
parent | e888dc0dde24d41223c89db6d13e8b90beb8c6fc (diff) | |
download | psutil-a6f03b9957d1be83f2c5cbe8099d7818ba581d89.tar.gz |
print sysinfo at the end of test run
-rw-r--r-- | psutil/arch/osx/process_info.c | 5 | ||||
-rw-r--r-- | psutil/tests/__init__.py | 41 | ||||
-rwxr-xr-x | psutil/tests/runner.py | 45 |
3 files changed, 47 insertions, 44 deletions
diff --git a/psutil/arch/osx/process_info.c b/psutil/arch/osx/process_info.c index 4b84a723..f83cfe47 100644 --- a/psutil/arch/osx/process_info.c +++ b/psutil/arch/osx/process_info.c @@ -261,7 +261,7 @@ psutil_get_environ(pid_t pid) { if ((errno == EINVAL) && (psutil_pid_exists(pid))) NoSuchProcess("sysctl"); else - PyErr_SetFromErrno(PyExc_OSError); + PyErr_SetFromOSErrnoWithSyscall("sysctl(KERN_PROCARGS2)"); goto error; } @@ -320,7 +320,6 @@ psutil_get_environ(pid_t pid) { free(procargs); free(procenv); - return py_ret; empty: @@ -353,7 +352,7 @@ psutil_get_kinfo_proc(pid_t pid, struct kinfo_proc *kp) { // now read the data from sysctl if (sysctl(mib, 4, kp, &len, NULL, 0) == -1) { // raise an exception and throw errno as the error - PyErr_SetFromErrno(PyExc_OSError); + PyErr_SetFromOSErrnoWithSyscall("sysctl"); return -1; } diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 811132fa..f95d3c1f 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -90,7 +90,7 @@ __all__ = [ # test utils 'unittest', 'skip_on_access_denied', 'skip_on_not_implemented', 'retry_on_failure', 'TestMemoryLeak', 'PsutilTestCase', - 'process_namespace', 'system_namespace', + 'process_namespace', 'system_namespace', 'print_sysinfo', # install utils 'install_pip', 'install_test_deps', # fs utils @@ -1047,6 +1047,45 @@ class TestMemoryLeak(PsutilTestCase): self.execute(call, **kwargs) +def print_sysinfo(): + import collections + import datetime + import getpass + import platform + + info = collections.OrderedDict() + info['OS'] = platform.system() + if psutil.OSX: + info['version'] = str(platform.mac_ver()) + elif psutil.WINDOWS: + info['version'] = ' '.join(map(str, platform.win32_ver())) + if hasattr(platform, 'win32_edition'): + info['edition'] = platform.win32_edition() + else: + info['version'] = platform.version() + if psutil.POSIX: + info['kernel'] = '.'.join(map(str, get_kernel_version())) + info['arch'] = ', '.join( + list(platform.architecture()) + [platform.machine()]) + info['hostname'] = platform.node() + info['python'] = ', '.join([ + platform.python_implementation(), + platform.python_version(), + platform.python_compiler()]) + if psutil.POSIX: + s = platform.libc_ver()[1] + if s: + info['glibc'] = s + info['fs-encoding'] = sys.getfilesystemencoding() + info['time'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + info['user'] = getpass.getuser() + info['pid'] = os.getpid() + print("=" * 70, flush=True) # NOQA + for k, v in info.items(): + print("%-14s %s" % (k + ':', v), flush=True) # NOQA + print("=" * 70, flush=True) # NOQA + + def _get_eligible_cpu(): p = psutil.Process() if hasattr(p, "cpu_num"): diff --git a/psutil/tests/runner.py b/psutil/tests/runner.py index 8a8443f0..35fea42a 100755 --- a/psutil/tests/runner.py +++ b/psutil/tests/runner.py @@ -45,6 +45,7 @@ from psutil._common import term_supports_colors from psutil._compat import super from psutil.tests import CI_TESTING from psutil.tests import import_module_by_path +from psutil.tests import print_sysinfo from psutil.tests import reap_children from psutil.tests import safe_rmpath from psutil.tests import TOX @@ -193,6 +194,8 @@ class ColouredTextRunner(unittest.TextTestRunner): def run(self, suite): result = self._run(suite) + if CI_TESTING: + print_sysinfo() self._exit(result.wasSuccessful()) @@ -277,6 +280,8 @@ class ParallelRunner(ColouredTextRunner): ser.testsRun, ser_fails, ser_errs, ser_skips, ser_elapsed))) print("Ran %s tests in %.3fs using %s workers" % ( par.testsRun + ser.testsRun, par_elapsed + ser_elapsed, NWORKERS)) + if CI_TESTING: + print_sysinfo() ok = par.wasSuccessful() and ser.wasSuccessful() self._exit(ok) @@ -310,46 +315,6 @@ def setup(): psutil._psplatform.cext.set_testing() -def print_sysinfo(): - import collections - import datetime - import getpass - import platform - from psutil.tests import get_kernel_version - - info = collections.OrderedDict() - info['OS'] = platform.system() - if psutil.OSX: - info['version'] = str(platform.mac_ver()) - elif psutil.WINDOWS: - info['version'] = ' '.join(map(str, platform.win32_ver())) - if hasattr(platform, 'win32_edition'): - info['edition'] = platform.win32_edition() - else: - info['version'] = platform.version() - if psutil.POSIX: - info['kernel'] = '.'.join(map(str, get_kernel_version())) - info['arch'] = ', '.join( - list(platform.architecture()) + [platform.machine()]) - info['hostname'] = platform.node() - info['python'] = ', '.join([ - platform.python_implementation(), - platform.python_version(), - platform.python_compiler()]) - if psutil.POSIX: - s = platform.libc_ver()[1] - if s: - info['glibc'] = s - info['fs-encoding'] = sys.getfilesystemencoding() - info['time'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - info['user'] = getpass.getuser() - info['pid'] = os.getpid() - print("=" * 70, flush=True) - for k, v in info.items(): - print("%-14s %s" % (k + ':', v), flush=True) - print("=" * 70, flush=True) - - def main(): setup() usage = "python3 -m psutil.tests [opts] [test-name]" |