小编Mat*_*shi的帖子

使用 pytest 运行单个测试方法失败(未找到)

我正在尝试使用以下命令在 Python 3.6 上使用 pytest 运行特定的测试方法:

pytest sanity_test.py::test_check
Run Code Online (Sandbox Code Playgroud)

(如 pytest文档中所述

它失败并显示以下错误消息:

ERROR: not found: <rootdir>/tests/automation/sanity/sanity_test.py::test_check
(no name '<rootdir>/tests/automation/sanity/sanity_test.py::test_check' in any of [<DoctestModule 'tests/automation/sanity/sanity_test.py'>, <Module 
'tests/automation/sanity/sanity_test.py'>])
Run Code Online (Sandbox Code Playgroud)

当我运行整个测试文件时,测试运行正常:

pytest sanity_test.py
Run Code Online (Sandbox Code Playgroud)

当我尝试在孤立项目中运行特定方法时,它运行良好。

pytest 无法在我的项目中具体找到我的测试方法的任何原因?

该文件非常简单,如下所示:

def test_check():
    pass
Run Code Online (Sandbox Code Playgroud)

python pytest python-3.x

7
推荐指数
1
解决办法
2084
查看次数

使用`psutils`有效地检索所有正在运行的进程的统计信息

我正在构建一个实用程序,它使用 Python 3.6.5 检索操作系统(Centos 7)上所有正在运行的进程的信息。

我为此创建了以下函数,使用psutil

def get_processes(self):
    fqdn = self.get_FQDN()
    process_infos = list()
    for proc in psutil.process_iter():
        proc_info = dict()
        with proc.oneshot():
            proc_info["pid"] = proc.pid
            proc_info["ppid"] = proc.ppid()
            proc_info["name"] = proc.name()
            proc_info["exe"] = proc.exe()  # Requires root access for '/proc/#/exe'
            proc_info["computer"] = fqdn
            proc_info["cpu_percent"] = proc.cpu_percent()

            mem_info = proc.memory_info()
            proc_info["mem_rss"] = mem_info.rss

            proc_info["num_threads"] = proc.num_threads()
            proc_info["nice_priority"] = proc.nice()
        process_infos.append(proc_info)
    return process_infos
Run Code Online (Sandbox Code Playgroud)

我有一个调用此函数的一秒迭代,在添加它之后,我注意到我的应用程序 CPU 消耗从 ~1% 恶化到 ~10%。探查器向我指出,我的大部分 CPU 时间都浪费在了解析文件内容的psutil's 函数_parse_stat_file/proc/<pid>/stat

根据 …

performance python-3.x psutil

4
推荐指数
1
解决办法
1102
查看次数

标签 统计

python-3.x ×2

performance ×1

psutil ×1

pytest ×1

python ×1