Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run specify testcase by command line #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions pyresttest/resttest.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class TestConfig:
variable_binds = None
generators = None # Map of generator name to generator function


def __str__(self):
return json.dumps(self, default=safe_to_json)

Expand Down Expand Up @@ -203,7 +204,7 @@ def parse_headers(header_string):
return [(k.lower(), v) for k, v in header_msg.items()]


def parse_testsets(base_url, test_structure, test_files=set(), working_directory=None, vars=None):
def parse_testsets(base_url, test_structure, test_files=set(), working_directory=None, vars=None,run_testcase=""):
""" Convert a Python data structure read from validated YAML to a set of structured testsets
The data structure is assumed to be a list of dictionaries, each of which describes:
- a tests (test structure)
Expand All @@ -221,6 +222,8 @@ def parse_testsets(base_url, test_structure, test_files=set(), working_directory
test_config = TestConfig()
testsets = list()
benchmarks = list()
run_testcase = run_testcase.strip() if run_testcase else ''
run_testcase = run_testcase.split(',') if run_testcase else []

if working_directory is None:
working_directory = os.path.abspath(os.getcwd())
Expand Down Expand Up @@ -253,6 +256,8 @@ def parse_testsets(base_url, test_structure, test_files=set(), working_directory
with cd(working_directory):
child = node[key]
mytest = Test.parse_test(base_url, child)
if run_testcase and mytest.name not in run_testcase:
continue
tests_out.append(mytest)
elif key == u'benchmark':
benchmark = parse_benchmark(base_url, node[key])
Expand Down Expand Up @@ -793,8 +798,9 @@ def main(args):
Keys allowed for args:
url - REQUIRED - Base URL
test - REQUIRED - Test file (yaml)
run_testcase - OPTIONAL - run a specify test case
print_bodies - OPTIONAL - print response body
print_headers - OPTIONAL - print response headers
print_headers - OPTIONAL - print response headers
log - OPTIONAL - set logging level {debug,info,warning,error,critical} (default=warning)
interactive - OPTIONAL - mode that prints info before and after test exectuion and pauses for user input for each test
absolute_urls - OPTIONAL - mode that treats URLs in tests as absolute/full URLs instead of relative URLs
Expand All @@ -817,6 +823,8 @@ def main(args):
test_file = args['test']
test_structure = read_test_file(test_file)

run_testcase = args['run_testcase']

my_vars = None
if 'vars' in args and args['vars'] is not None:
my_vars = yaml.safe_load(args['vars'])
Expand All @@ -830,7 +838,7 @@ def main(args):
base_url = ''

tests = parse_testsets(base_url, test_structure,
working_directory=os.path.dirname(test_file), vars=my_vars)
working_directory=os.path.dirname(test_file), vars=my_vars, run_testcase=run_testcase)

# Override configs from command line if config set
for t in tests:
Expand Down Expand Up @@ -874,6 +882,8 @@ def parse_command_line_args(args_in):
u"--url", help="Base URL to run tests against", action="store", type="string")
parser.add_option(u"--test", help="Test file to use",
action="store", type="string")
parser.add_option(u"--run_testcase", help="To run a specify test in file(identify by name, split multiple test by ,)",
action="store", type="string")
parser.add_option(u'--import_extensions',
help='Extensions to import, separated by semicolons', action="store", type="string")
parser.add_option(
Expand Down