Skip to content

Commit 21b4c5f

Browse files
committed
Simplify selected attributes from ps output
This silent mypy errors about type of "attributes" being changed on the fly.
1 parent 8108def commit 21b4c5f

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

testinfra/modules/process.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,10 @@ class PosixProcess(Process):
122122

123123
def _get_processes(self, **filters):
124124
cmd = "ps -Aww -o %s"
125-
attributes = {"pid", "comm", "pcpu", "pmem"} | set(filters.keys())
126-
127-
# Theses attributes contains spaces. Put them at the end of the list
128-
attributes -= {"lstart", "args"}
129-
attributes = sorted(attributes)
130-
attributes.extend(["lstart", "args"])
125+
# lstart and args attributes contains spaces. Put them at the end of the list
126+
attributes = sorted(
127+
({"pid", "comm", "pcpu", "pmem"} | set(filters)) - {"lstart", "args"}
128+
) + ["lstart", "args"]
131129
arg = ":50,".join(attributes)
132130

133131
procs = []
@@ -155,12 +153,10 @@ def _get_process_attribute_by_pid(self, pid, name):
155153
class BusyboxProcess(Process):
156154
def _get_processes(self, **filters):
157155
cmd = "ps -A -o %s"
158-
attributes = {"pid", "comm", "time"} | set(filters.keys())
159-
160-
# Theses attributes contains spaces. Put them at the end of the list
161-
attributes -= {"args"}
162-
attributes = sorted(attributes)
163-
attributes.extend(["args"])
156+
# "args" attribute contains spaces. Put them at the end of the list
157+
attributes = sorted(({"pid", "comm", "time"} | set(filters)) - {"args"}) + [
158+
"args"
159+
]
164160
arg = ",".join(attributes)
165161

166162
procs = []

0 commit comments

Comments
 (0)