fix: ensure compatibility with deprecated cli args in v2

This commit is contained in:
debugtalk
2020-05-28 16:51:00 +08:00
parent ab5c49c05d
commit d0a289c6bf
6 changed files with 179 additions and 97 deletions

View File

@@ -9,6 +9,7 @@ from httprunner import __description__, __version__
from httprunner.ext.har2case import init_har2case_parser, main_har2case
from httprunner.ext.make import init_make_parser, main_make
from httprunner.ext.scaffold import init_parser_scaffold, main_scaffold
from httprunner.compat import ensure_cli_args
def init_parser_run(subparsers):
@@ -40,6 +41,7 @@ def main_run(extra_args):
sys.exit(1)
extra_args_new.extend(testcase_path_list)
extra_args_new = ensure_cli_args(extra_args_new)
pytest.main(extra_args_new)

View File

@@ -146,3 +146,23 @@ def ensure_testcase_v3(test_content: Dict) -> Dict:
v3_content["teststeps"].append(teststep)
return v3_content
def ensure_cli_args(args: List) -> List:
""" ensure compatibility with deprecated cli args in v2
"""
# remove deprecated --failfast
if "--failfast" in args:
args.pop(args.index("--failfast"))
# convert --report-file to --html
if "--report-file" in args:
index = args.index("--report-file")
args[index] = "--html"
args.append("--self-contained-html")
# remove deprecated --save-tests
if "--save-tests" in args:
args.pop(args.index("--save-tests"))
return args

View File

@@ -134,3 +134,28 @@ class TestCompat(unittest.TestCase):
],
},
)
def test_ensure_cli_args(self):
args1 = ["/path/to/testcase.yml", "--failfast"]
self.assertEqual(compat.ensure_cli_args(args1), ["/path/to/testcase.yml"])
args2 = ["/path/to/testcase.yml", "--save-tests"]
self.assertEqual(compat.ensure_cli_args(args2), ["/path/to/testcase.yml"])
args3 = ["/path/to/testcase.yml", "--report-file", "report.html"]
self.assertEqual(
compat.ensure_cli_args(args3),
["/path/to/testcase.yml", "--html", "report.html", "--self-contained-html"],
)
args4 = [
"/path/to/testcase.yml",
"--failfast",
"--save-tests",
"--report-file",
"report.html"
]
self.assertEqual(
compat.ensure_cli_args(args4),
["/path/to/testcase.yml", "--html", "report.html", "--self-contained-html"],
)