From fcecedc10e7c672288de5f9bead0d497673a4204 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 26 Jul 2019 03:13:46 +0530 Subject: unit tests: Convert unittest args to pytest Allows people to run specific tests and/or enable verbose mode. --- run_unittests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/run_unittests.py b/run_unittests.py index 1ac4c5335..0bd2c027b 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -6605,6 +6605,21 @@ def unset_envs(): if v in os.environ: del os.environ[v] +def convert_args(argv): + # If we got passed a list of tests, pass it on + pytest_args = ['-v'] if '-v' in argv else [] + test_list = [] + for arg in argv: + if arg.startswith('-'): + continue + # ClassName.test_name => 'ClassName and test_name' + if '.' in arg: + arg = ' and '.join(arg.split('.')) + test_list.append(arg) + if test_list: + pytest_args += ['-k', ' or '.join(test_list)] + return pytest_args + def main(): unset_envs() try: @@ -6612,6 +6627,7 @@ def main(): # Need pytest-xdist for `-n` arg import xdist # noqa: F401 pytest_args = ['-n', 'auto', './run_unittests.py'] + pytest_args += convert_args(sys.argv[1:]) return subprocess.run(python_command + ['-m', 'pytest'] + pytest_args).returncode except ImportError: print('pytest-xdist not found, using unittest instead') -- cgit v1.2.3