From 777facc69c792356ace880d5c19a7f8f9cf1da51 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 8 Sep 2021 18:46:56 +0200 Subject: [PATCH] #1784 - init commit of pype command Pype command is better than run_tests.ps1 as OP is initialized by start.py. This is more similar to standard running of OP --- openpype/cli.py | 15 +++++++++++++++ openpype/pype_commands.py | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/openpype/cli.py b/openpype/cli.py index 18cc1c63cd..c69407e295 100644 --- a/openpype/cli.py +++ b/openpype/cli.py @@ -283,3 +283,18 @@ def run(script): args_string = " ".join(args[1:]) print(f"... running: {script} {args_string}") runpy.run_path(script, run_name="__main__", ) + + +@main.command() +@click.argument("folder", nargs=-1) +@click.option("-m", + "--mark", + help="Run tests marked by", + default=None) +@click.option("-p", + "--pyargs", + help="Run tests from package", + default=None) +def runtests(folder, mark, pyargs): + """Run all automatic tests after proper initialization via start.py""" + PypeCommands().run_tests(folder, mark, pyargs) diff --git a/openpype/pype_commands.py b/openpype/pype_commands.py index c18fe36667..c309ee8c09 100644 --- a/openpype/pype_commands.py +++ b/openpype/pype_commands.py @@ -257,3 +257,24 @@ class PypeCommands: def validate_jsons(self): pass + def run_tests(self, folder, mark, pyargs): + """ + Runs tests from 'folder' + + Args: + folder (str): relative path to folder with tests + mark (str): label to run tests marked by it (slow etc) + pyargs (str): package path to test + """ + print("run_tests") + import subprocess + folder = folder or "../tests" + mark_str = pyargs_str = '' + if mark: + mark_str = "- m {}".format(mark) + + if pyargs: + pyargs_str = "--pyargs {}".format(pyargs) + + subprocess.run("pytest {} {} {}".format(folder, mark_str, pyargs_str)) +