diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index ff74892944..d5e02c26d8 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -605,6 +605,8 @@ testCompareXMLToArgv(const void *data)
     return ret;
 }
 
+# define TEST_CAPS_PATH abs_srcdir "/qemucapabilitiesdata/caps_"
+
 typedef enum {
     ARG_QEMU_CAPS = 1,
     ARG_GIC,
@@ -612,20 +614,25 @@ typedef enum {
     ARG_MIGRATE_FD,
     ARG_FLAGS,
     ARG_PARSEFLAGS,
+    ARG_CAPS_ARCH,
+    ARG_CAPS_VER,
 
     ARG_END = QEMU_CAPS_LAST,
 } testInfoArgNames;
 
 static int
-testInfoSetArgs(struct testInfo *info, ...)
+testInfoSetArgs(struct testInfo *info, virHashTablePtr capslatest, ...)
 {
     va_list argptr;
     testInfoArgNames argname;
     virQEMUCapsPtr qemuCaps = NULL;
     int gic = GIC_NONE;
     int ret = -1;
+    char *capsarch = NULL;
+    char *capsver = NULL;
+    VIR_AUTOFREE(char *) capsfile = NULL;
 
-    va_start(argptr, info);
+    va_start(argptr, capslatest);
     while ((argname = va_arg(argptr, int)) < ARG_END) {
         switch (argname) {
         case ARG_QEMU_CAPS:
@@ -654,6 +661,14 @@ testInfoSetArgs(struct testInfo *info, ...)
             info->parseFlags = va_arg(argptr, int);
             break;
 
+        case ARG_CAPS_ARCH:
+            capsarch = va_arg(argptr, char *);
+            break;
+
+        case ARG_CAPS_VER:
+            capsver = va_arg(argptr, char *);
+            break;
+
         case ARG_END:
         default:
             fprintf(stderr, "Unexpected test info argument");
@@ -661,13 +676,33 @@ testInfoSetArgs(struct testInfo *info, ...)
         }
     }
 
-    if (!info->qemuCaps) {
-        if (!qemuCaps) {
-            fprintf(stderr, "No qemuCaps generated\n");
+    if (!qemuCaps && capsarch && capsver) {
+        bool stripmachinealiases = false;
+
+        if (STREQ(capsver, "latest")) {
+            if (VIR_STRDUP(capsfile, virHashLookup(capslatest, capsarch)) < 0)
+                goto cleanup;
+            stripmachinealiases = true;
+        } else if (virAsprintf(&capsfile,
+                               TEST_CAPS_PATH "%s.%s.xml",
+                               capsver, capsarch) < 0) {
             goto cleanup;
         }
-        VIR_STEAL_PTR(info->qemuCaps, qemuCaps);
+
+        if (!(qemuCaps = qemuTestParseCapabilitiesArch(virArchFromString(capsarch),
+                                                       capsfile)))
+            goto cleanup;
+
+        if (stripmachinealiases)
+            virQEMUCapsStripMachineAliases(qemuCaps);
+        info->flags |= FLAG_REAL_CAPS;
+    }
+
+    if (!qemuCaps) {
+        fprintf(stderr, "No qemuCaps generated\n");
+        goto cleanup;
     }
+    VIR_STEAL_PTR(info->qemuCaps, qemuCaps);
 
     if (gic && testQemuCapsSetGIC(info->qemuCaps, gic) < 0)
         goto cleanup;
@@ -806,7 +841,6 @@ mymain(void)
  * the test cases should be forked using DO_TEST_CAPS_VER with the appropriate
  * version.
  */
-# define TEST_CAPS_PATH abs_srcdir "/qemucapabilitiesdata/caps_"
 
 # define DO_TEST_CAPS_INTERNAL(_name, arch, ver, ...) \
     do { \
@@ -814,20 +848,11 @@ mymain(void)
             .name = _name, \
             .suffix = "." arch "-" ver, \
         }; \
-        static const char *capsfile = TEST_CAPS_PATH ver "." arch ".xml"; \
-        static bool stripmachinealiases; \
-        if (STREQ(ver, "latest")) { \
-            capsfile = virHashLookup(capslatest, arch); \
-            stripmachinealiases = true; \
-        } \
-        if (!(info.qemuCaps = qemuTestParseCapabilitiesArch(virArchFromString(arch), \
-                                                            capsfile))) \
-            return EXIT_FAILURE; \
-        if (stripmachinealiases) \
-            virQEMUCapsStripMachineAliases(info.qemuCaps); \
-        if (testInfoSetArgs(&info, __VA_ARGS__, ARG_END) < 0) \
+        if (testInfoSetArgs(&info, capslatest, \
+                            ARG_CAPS_ARCH, arch, \
+                            ARG_CAPS_VER, ver, \
+                            __VA_ARGS__, ARG_END) < 0) \
             return EXIT_FAILURE; \
-        info.flags |= FLAG_REAL_CAPS; \
         if (virTestRun("QEMU XML-2-ARGV " _name "." arch "-" ver, \
                        testCompareXMLToArgv, &info) < 0) \
             ret = -1; \
@@ -865,7 +890,8 @@ mymain(void)
         static struct testInfo info = { \
             .name = _name, \
         }; \
-        if (testInfoSetArgs(&info, __VA_ARGS__, QEMU_CAPS_LAST, ARG_END) < 0) \
+        if (testInfoSetArgs(&info, capslatest, \
+                            __VA_ARGS__, QEMU_CAPS_LAST, ARG_END) < 0) \
             return EXIT_FAILURE; \
         if (virTestRun("QEMU XML-2-ARGV " _name, \
                        testCompareXMLToArgv, &info) < 0) \
