You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qemu/docs/devel/testing
Fabiano Rosas 11d99e98fe tests/functional: Allow tests to be run individually
The functional tests currently don't allow a single test to be
selected for execution by dotted name, e.g:

./build/run tests/functional/ppc64/test_pseries.py PseriesMachine.test_ppc64_linux_boot
                                          ^
The issue is that the testcase.py main function passes the test
module's name as the second argument to unittest.main(), which makes
it ignore all other positional arguments (presumably because the
module is already the superset of all tests).

After commit cac08383f0 ("tests/functional: expose sys.argv to
unittest.main"), the situation improves by passing the rest of the
argv from the command line invocation into unittest.main(), but it
still doesn't fix the issue. The short form options are now accepted,
so the -k option could be used to filter for a pattern, which is
useful, but not the same as listing the test names.

Fix this by passing the test module name via the "module" argument to
unittest.main() and stop touching argv. The ways of invoking tests are
now as per unittests documentation (-k still works):

  Examples:
    test_pseries.py                           - run default set of tests
    test_pseries.py MyTestSuite               - run suite 'MyTestSuite'
    test_pseries.py MyTestCase.testSomething  - run MyTestCase.testSomething
    test_pseries.py MyTestCase                - run all 'test*' test methods in MyTestCase

Note that ever since we've been programatically passing the module
name to unittest.main(), the usage 'test_pseries.py test_pseries' was
never valid. It used to "work" just the same as 'test_pseries.py
foobar' would. After this patch, that usage results in an error.

Also note that testcase.py:main() pertains to running the test module
that invoked it via QemuSystemTest.main(), i.e. module == __main__. So
the 'discover' usage of unittest doesn't apply here, the module is
already discovered because that's where this code was called from to
begin with. This patch could just as well call unittest.main() instead
of unittest.main(test_module), but the latter provides nicer error
messages prefixed with the module name.

Tested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
Message-ID: <20260102181700.11886-1-farosas@suse.de>
Signed-off-by: Thomas Huth <thuth@redhat.com>
1 week ago
..
acpi-bits.rst docs: avoid footnotes consisting of just URLs 1 year ago
blkdebug.rst docs/devel/blkdebug: Convert to rST format 1 year ago
blkverify.rst docs/devel/blkverify: Convert to rST format 1 year ago
ci-jobs.rst.inc gitlab: add initial ppc64le custom-runner test 2 months ago
ci-runners.rst.inc
ci.rst docs/devel/testing: Dissolve the ci-definitions.rst.inc file 9 months ago
functional.rst tests/functional: Allow tests to be run individually 1 week ago
fuzzing.rst docs/devel/testing/fuzzing: Note that you can get qtest to read from a file 2 months ago
index.rst Remove the remainders of the Avocado tests 9 months ago
main.rst qapi: switch to use QEMU_TEST_REGENERATE env var 4 months ago
qgraph.rst
qtest.rst docs/devel: add a codebase section 1 year ago