osmith has uploaded this change for review.

View Change

testenv: fix B006

Fix "B006 Do not use mutable data structures for argument defaults". I
ran into bugs caused by this a couple of times actually, it is good to
check for that.

Related: https://docs.astral.sh/ruff/rules/mutable-argument-default/
Change-Id: Id860c1cba20c0218aa1d1bb17378a0f5a521cfe0
---
M .ruff.toml
M _testenv/testenv/cmd.py
M _testenv/testenv/podman.py
3 files changed, 14 insertions(+), 6 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/20/43120/1
diff --git a/.ruff.toml b/.ruff.toml
index ad4de47..5b6da16 100644
--- a/.ruff.toml
+++ b/.ruff.toml
@@ -5,7 +5,6 @@

[lint]
ignore = [
- "B006",
"B026",
"BLE001",
"DTZ001",
diff --git a/_testenv/testenv/cmd.py b/_testenv/testenv/cmd.py
index c14f694..97e5c0d 100644
--- a/_testenv/testenv/cmd.py
+++ b/_testenv/testenv/cmd.py
@@ -88,7 +88,8 @@
raise RuntimeError("shell command related error, find details right above this python trace")


-def generate_env(env={}, podman=False):
+def generate_env(env=None, podman=False):
+ env = env or {}
ret = dict(env_extra)
path = os.path.join(testenv.data_dir, "scripts")
path += f":{os.path.join(testenv.data_dir, 'scripts/qemu')}"
@@ -120,7 +121,8 @@
return ret


-def run(cmd, check=True, env={}, no_podman=False, stdin=subprocess.DEVNULL, *args, **kwargs):
+def run(cmd, check=True, env=None, no_podman=False, stdin=subprocess.DEVNULL, *args, **kwargs):
+ env = env or {}
if not no_podman and testenv.args.podman:
return testenv.podman.exec_cmd(cmd, check=check, env=env, *args, **kwargs)

diff --git a/_testenv/testenv/podman.py b/_testenv/testenv/podman.py
index a3e7948..eefa911 100644
--- a/_testenv/testenv/podman.py
+++ b/_testenv/testenv/podman.py
@@ -82,7 +82,8 @@
)


-def generate_env_podman(env={}):
+def generate_env_podman(env=None):
+ env = env or {}
ret = []

for key, val in testenv.cmd.generate_env(env, True).items():
@@ -136,7 +137,10 @@
run_shell_on_stop = True


-def exec_cmd(cmd, podman_opts=[], cwd=None, env={}, *args, **kwargs):
+def exec_cmd(cmd, podman_opts=None, cwd=None, env=None, *args, **kwargs):
+ podman_opts = podman_opts or []
+ env = env or {}
+
if not container_name:
raise RuntimeError(f"Attempting to execute a command in podman, but the container isn't running anymore: {cmd}")

@@ -159,7 +163,10 @@
)


-def exec_cmd_background(cmd, podman_opts=[], cwd=None, env={}):
+def exec_cmd_background(cmd, podman_opts=None, cwd=None, env=None):
+ podman_opts = podman_opts or []
+ env = env or {}
+
podman_opts = list(podman_opts) + generate_env_podman(env)

if cwd:

To view, visit change 43120. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Id860c1cba20c0218aa1d1bb17378a0f5a521cfe0
Gerrit-Change-Number: 43120
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith@sysmocom.de>