Skip to content

The testname directive

Richard R. Drake edited this page Jun 8, 2022 · 1 revision

The "testname" directive can be used to set the name of a test to one different from the filename, and to define multiple test names (multiple test instances) in the same file.

If a test file was named atest.vvt and had contents

#VVT: testname : foobar
import vvtest_util as vvt
...

then vvtest would create a test instance with name "foobar" (even though the file name was atest.vvt).

Multiple test instances with different names

Each "testname" directive will create a new test instance with a different name. Of course, the script used to execute the test will be the same file. For example,

#VVT: testname = foo
#VVT: testname = bar

import vvtest_util as vvt

if vvt.NAME == 'foo':
    do_foo_stuff()
elif vvt.NAME == 'bar':
    do_bar_stuff()

This file would result in two tests: "foo" and "bar". Note that "name" is an alias for "testname", so the above could also be done like this

#VVT: name = foo
#VVT: name = bar
...

The testname attribute

Other directives in the test header can be made to apply to a specific test name. For example,

#VVT: testname = foo
#VVT: testname = bar
#VVT: keywords (testname=foo) : animal vegetable
#VVT: timeout (testname=bar) = 1h

Here, only test "foo" will have the animal and vegetable keywords, and the one hour timeout only applies to the test "bar".

Special dependency syntax

Tests defined within one test file using the "testname" directive can be made to depend on each other. For example,

#VVT: testname = foo
#VVT: testname = bar
#VVT: depends on (testname=bar) : foo

Here, the test "bar" is made to depend on the test "foo". There is a short hand syntax which will accomplish the same thing:

#VVT: testname = foo
#VVT: testname = bar (depends on=foo)

The syntax in the parentheses is the same as general attribute syntax, with allowable attribute names being "depends on", "result", and "expect". More about dependencies is in the documentation on general test dependencies.

Clone this wiki locally