Skip to content

Commit

Permalink
added support for --testcase flag in ansible-test (ansible#36134)
Browse files Browse the repository at this point in the history
* added support for --testcase flag in ansible-test

* fixed command format

* added tab completion

* fixed sanity issues

* added documenation for --testcase

* don't autocomplete when multiple modules are selected
  • Loading branch information
newswangerd authored and nitzmahone committed Feb 14, 2018
1 parent dba561e commit 3f5caf6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/docsite/rst/dev_guide/testing_integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ To run integration tests for a specific module::

ansible-test network-integration --inventory /path/to/ansible/test/integration/inventory.networking vyos_vlan

To run a single test case on a specific module::

# Only run vyos_vlan/tests/cli/basic.yaml
ansible-test network-integration --inventory /path/to/ansible/test/integration/inventory.networking vyos_vlan --testcase basic

To run integration tests for a specific transport::

# Only run nxapi test
Expand Down
1 change: 1 addition & 0 deletions test/runner/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def __init__(self, args):

self.platform = args.platform # type: list [str]
self.inventory = args.inventory # type: str
self.testcase = args.testcase # type: str


class UnitsConfig(TestConfig):
Expand Down
4 changes: 4 additions & 0 deletions test/runner/lib/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ def command_integration_role(args, target, start_at_task):
if args.diff:
cmd += ['--diff']

if isinstance(args, NetworkIntegrationConfig):
if args.testcase:
cmd += ['-e', 'testcase=%s' % args.testcase]

if args.verbosity:
cmd.append('-' + ('v' * args.verbosity))

Expand Down
29 changes: 29 additions & 0 deletions test/runner/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def parse_args():
metavar='PATH',
help='path to inventory used for tests')

network_integration.add_argument('--testcase',
metavar='TESTCASE',
help='limit a test to a specified testcase').completer = complete_network_testcase

windows_integration = subparsers.add_parser('windows-integration',
parents=[integration],
help='windows integration tests')
Expand Down Expand Up @@ -648,6 +652,31 @@ def complete_network_platform(prefix, parsed_args, **_):
return [i for i in images if i.startswith(prefix) and (not parsed_args.platform or i not in parsed_args.platform)]


def complete_network_testcase(prefix, parsed_args, **_):
"""
:type prefix: unicode
:type parsed_args: any
:rtype: list[str]
"""
testcases = []

# since testcases are module specific, don't autocomplete if more than one
# module is specidied
if len(parsed_args.include) != 1:
return []

test_dir = 'test/integration/targets/%s/tests' % parsed_args.include[0]
connections = os.listdir(test_dir)

for conn in connections:
if os.path.isdir(os.path.join(test_dir, conn)):
for testcase in os.listdir(os.path.join(test_dir, conn)):
if testcase.startswith(prefix):
testcases.append(testcase.split('.')[0])

return testcases


def complete_sanity_test(prefix, parsed_args, **_):
"""
:type prefix: unicode
Expand Down

0 comments on commit 3f5caf6

Please sign in to comment.