From 2f2116b4bda283fa9b8e20464a97fb8a3dd25fc7 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Thu, 9 Dec 2021 18:30:43 +0100 Subject: [PATCH] OP-2042 - added test_data_folder to command line --- openpype/cli.py | 8 ++++++-- openpype/pype_commands.py | 18 +++++++++--------- tests/integration/conftest.py | 12 ++++++++++++ tests/lib/testing_classes.py | 8 ++++---- 4 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 tests/integration/conftest.py diff --git a/openpype/cli.py b/openpype/cli.py index 4c4dc1a3c6..1f444006ca 100644 --- a/openpype/cli.py +++ b/openpype/cli.py @@ -356,9 +356,13 @@ def run(script): "--pyargs", help="Run tests from package", default=None) -def runtests(folder, mark, pyargs): +@click.option("-t", + "--test_data_folder", + help="Unzipped directory path of test file", + default=None) +def runtests(folder, mark, pyargs, test_data_folder): """Run all automatic tests after proper initialization via start.py""" - PypeCommands().run_tests(folder, mark, pyargs) + PypeCommands().run_tests(folder, mark, pyargs, test_data_folder) @main.command() diff --git a/openpype/pype_commands.py b/openpype/pype_commands.py index f01c6f0e42..7b3c799b3c 100644 --- a/openpype/pype_commands.py +++ b/openpype/pype_commands.py @@ -341,7 +341,7 @@ class PypeCommands: def validate_jsons(self): pass - def run_tests(self, folder, mark, pyargs): + def run_tests(self, folder, mark, pyargs, test_data_folder): """ Runs tests from 'folder' @@ -349,26 +349,26 @@ class PypeCommands: 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 + test_data_folder (str): url to unzipped folder of test data """ print("run_tests") - import subprocess - if folder: folder = " ".join(list(folder)) else: folder = "../tests" - mark_str = pyargs_str = '' + # disable warnings and show captured stdout even if success + args = ["--disable-pytest-warnings", "-rP", folder] + if mark: - mark_str = "-m {}".format(mark) + args.extend(["-m", mark]) if pyargs: - pyargs_str = "--pyargs {}".format(pyargs) + args.extend(["--pyargs", pyargs]) - # disable warnings and show captured stdout even if success - args = ["--disable-pytest-warnings", "-rP"] + if test_data_folder: + args.extend(["--test_data_folder", test_data_folder]) - args += [folder, mark_str, pyargs_str] print("run_tests args: {}".format(args)) import pytest pytest.main(args) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py new file mode 100644 index 0000000000..bc002e8f86 --- /dev/null +++ b/tests/integration/conftest.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +import pytest + +def pytest_addoption(parser): + parser.addoption( + "--test_data_folder", action="store", default=None, + help="Provide url of a folder of unzipped test file" + ) + +@pytest.fixture(scope="module") +def test_data_folder(request): + return request.config.getoption("--test_data_folder") \ No newline at end of file diff --git a/tests/lib/testing_classes.py b/tests/lib/testing_classes.py index 25ad66cdfb..541a92d15d 100644 --- a/tests/lib/testing_classes.py +++ b/tests/lib/testing_classes.py @@ -58,10 +58,10 @@ class ModuleUnitTest(BaseTest): m.undo() @pytest.fixture(scope="module") - def download_test_data(self): - if self.TEST_DATA_FOLDER: - print("Using existing folder {}".format(self.TEST_DATA_FOLDER)) - yield self.TEST_DATA_FOLDER + def download_test_data(self, test_data_folder): + if test_data_folder: + print("Using existing folder {}".format(test_data_folder)) + yield test_data_folder else: tmpdir = tempfile.mkdtemp() for test_file in self.TEST_FILES: