[PATCH 4/7] test: conftest: don't call .startswith on int

Ahmad Fatoum
2026-04-13T07:46:06Z

The returned YAML value may be an integer if quotes are missing, which
will lead to an error when .startswith() is called on it.

Check that the value is a string first and while at it, combine the two
loops to reduce the duplicate code.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
conftest.py | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/conftest.py b/conftest.py
index c27e7a9546a1..6bf92f3afed7 100644
--- a/conftest.py
+++ b/conftest.py
@@ -226,25 +226,17 @@ def strategy(request, target, pytestconfig): # noqa: max-complexity=30
else:
pytest.exit("--blk unsupported for target\n", 1)

+ envopts = {}
+
for i, fw_cfg in enumerate(pytestconfig.option.qemu_fw_cfg):
+ value = fw_cfg.pop()
+ envpath = fw_cfg.pop() if fw_cfg else f"data/fw_cfg{i}"
+
+ envopts[envpath] = value
+
+ for envpath, value in (yaml_env | envopts).items():
if virtio:
- value = fw_cfg.pop()
- envpath = fw_cfg.pop() if fw_cfg else f"data/fw_cfg{i}"
-
- if value.startswith('@'):
- source = f"file='{value[1:]}'"
- else:
- source = f"string='{value}'"
-
- strategy.append_qemu_args(
- '-fw_cfg', f'name=opt/org.barebox.env/{envpath},{source}'
- )
- else:
- pytest.exit("--env unsupported for target\n", 1)
-
- for envpath, value in yaml_env.items():
- if virtio:
- if value.startswith('@'):
+ if isinstance(value, str) and value.startswith('@'):
source = f"file='{value[1:]}'"
else:
source = f"string='{value}'"
--
2.47.3