On Fri, Jul 18, 2025 at 12:37 PM Paolo Bonzini <pbonz...@redhat.com> wrote:
>
> On 7/18/25 11:12, Manos Pitsidianakis wrote:
> > Add a CLI argument that takes fnmatch(3)-style patterns as value and can
> > be specified many times. Only tests that match the pattern will be
> > executed. This argument is passed to unittest.main which takes the same
> > argument.
> >
> > Signed-off-by: Manos Pitsidianakis <manos.pitsidiana...@linaro.org>
> > ---
> >   tests/functional/qemu_test/testcase.py | 14 +++++++++++++-
> >   1 file changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/tests/functional/qemu_test/testcase.py 
> > b/tests/functional/qemu_test/testcase.py
> > index 
> > 4455fcc38016c14db04019bbd64eaae9b47363c1..b7a660fd729afe39ff8cf7a0be97c2fc2f2f573f
> >  100644
> > --- a/tests/functional/qemu_test/testcase.py
> > +++ b/tests/functional/qemu_test/testcase.py
> > @@ -55,6 +55,14 @@ def parse_args(test_name: str) -> argparse.Namespace:
> >           action="store_true",
> >           help="List all tests that would be executed and exit.",
> >       )
> > +    parser.add_argument(
> > +        "-k",
> > +        dest="test_name_patterns",
> > +        action="append",
> > +        type=str,
> > +        help="Only run tests which match the given substring. "
> > +        "This argument is passed to unittest.main verbatim.",
> > +    )
> >       return parser.parse_args()
> >
> >
> > @@ -301,8 +309,12 @@ def main():
> >
> >           tr = pycotap.TAPTestRunner(message_log = 
> > pycotap.LogMode.LogToError,
> >                                      test_output_log = 
> > pycotap.LogMode.LogToError)
> > +        argv = ["__dummy__", path] + (
> > +            (["-k"] + args.test_name_patterns)
> > +            if args.test_name_patterns else []
> > +        )
>
> This does not work for >1 occurrences of -k. Maybe something like:
>
> argv = list(itertools.chain(
>      ["__dummy__", "path"],
>      *[["-k", x] for x in args.test_name_patterns]))


Oops, good catch!

Thanks

> Paolo
>
> >           res = unittest.main(module = None, testRunner = tr, exit = False,
> > -                            argv=["__dummy__", path])
> > +                            argv=argv)
> >           for (test, message) in res.result.errors + res.result.failures:
> >
> >               if hasattr(test, "log_filename"):
> >
>

Reply via email to