diff --git a/openpype/cli.py b/openpype/cli.py index 1f444006ca..6b20fb5203 100644 --- a/openpype/cli.py +++ b/openpype/cli.py @@ -360,9 +360,18 @@ def run(script): "--test_data_folder", help="Unzipped directory path of test file", default=None) -def runtests(folder, mark, pyargs, test_data_folder): +@click.option("-s", + "--persist", + help="Persist test DB and published files after test end", + default=None) +@click.option("-a", + "--app_variant", + help="Provide specific app variant for test, empty for latest", + default=None) +def runtests(folder, mark, pyargs, test_data_folder, persist, app_variant): """Run all automatic tests after proper initialization via start.py""" - PypeCommands().run_tests(folder, mark, pyargs, test_data_folder) + PypeCommands().run_tests(folder, mark, pyargs, test_data_folder, + persist, app_variant) @main.command() diff --git a/openpype/pype_commands.py b/openpype/pype_commands.py index 7b3c799b3c..a6330bae1f 100644 --- a/openpype/pype_commands.py +++ b/openpype/pype_commands.py @@ -341,7 +341,8 @@ class PypeCommands: def validate_jsons(self): pass - def run_tests(self, folder, mark, pyargs, test_data_folder): + def run_tests(self, folder, mark, pyargs, + test_data_folder, persist, app_variant): """ Runs tests from 'folder' @@ -350,6 +351,10 @@ class PypeCommands: 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 + persist (bool): True if keep test db and published after test + end + app_variant (str): variant (eg 2020 for AE), empty if use + latest installed version """ print("run_tests") if folder: @@ -366,9 +371,15 @@ class PypeCommands: if pyargs: args.extend(["--pyargs", pyargs]) - if test_data_folder: + if persist: args.extend(["--test_data_folder", test_data_folder]) + if persist: + args.extend(["--persist", persist]) + + if app_variant: + args.extend(["--app_variant", app_variant]) + print("run_tests args: {}".format(args)) import pytest pytest.main(args) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index bc002e8f86..400c0dcc2a 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,12 +1,35 @@ # -*- coding: utf-8 -*- +# adds command line arguments for 'runtests' as a fixtures 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" ) + parser.addoption( + "--persist", action="store", default=None, + help="True - keep test_db, test_openpype, outputted test files" + ) + + parser.addoption( + "--app_variant", action="store", default=None, + help="Keep empty to locate latest installed variant or explicit" + ) + + @pytest.fixture(scope="module") def test_data_folder(request): - return request.config.getoption("--test_data_folder") \ No newline at end of file + return request.config.getoption("--test_data_folder") + + +@pytest.fixture(scope="module") +def persist(request): + return request.config.getoption("--persist") + + +@pytest.fixture(scope="module") +def app_variant(request): + return request.config.getoption("--app_variant") diff --git a/tests/integration/hosts/nuke/test_publish_in_nuke.py b/tests/integration/hosts/nuke/test_publish_in_nuke.py index 092fd7d1c6..a5a09bdd04 100644 --- a/tests/integration/hosts/nuke/test_publish_in_nuke.py +++ b/tests/integration/hosts/nuke/test_publish_in_nuke.py @@ -27,22 +27,23 @@ class TestPublishInNuke(PublishTest): To check log/errors from launched app's publish process keep PERSIST to True and check `test_openpype.logs` collection. """ - PERSIST = True # True - keep test_db, test_openpype, outputted test files - + # https://drive.google.com/file/d/1SUurHj2aiQ21ZIMJfGVBI2KjR8kIjBGI/view?usp=sharing # noqa: E501 TEST_FILES = [ ("1SUurHj2aiQ21ZIMJfGVBI2KjR8kIjBGI", "test_Nuke_publish.zip", "") ] APP = "nuke" - # keep empty to locate latest installed variant or explicit - APP_VARIANT = "" TIMEOUT = 120 # publish timeout - TEST_DATA_FOLDER = "C:\\Users\\petrk\\AppData\\Local\\Temp\\tmpbfh976y6" # provide existing folder with test data + # could be overwritten by command line arguments + # keep empty to locate latest installed variant or explicit + APP_VARIANT = "" + PERSIST = True # True - keep test_db, test_openpype, outputted test files + TEST_DATA_FOLDER = None @pytest.fixture(scope="module") - def last_workfile_path(self, download_test_data): + def last_workfile_path(self, download_test_data, output_folder_url): """Get last_workfile_path from source data. """ @@ -99,7 +100,7 @@ class TestPublishInNuke(PublishTest): "name": "workfileTest_task"}), \ "workfileTest_task subset must be present" - assert 10 == dbcon.count_documents({"type": "representation"}), \ + assert 4 == dbcon.count_documents({"type": "representation"}), \ "Not expected no of representations" reprs = dbcon.count_documents({"type": "representation", diff --git a/tests/lib/testing_classes.py b/tests/lib/testing_classes.py index 96e7148bff..40363e928f 100644 --- a/tests/lib/testing_classes.py +++ b/tests/lib/testing_classes.py @@ -7,6 +7,7 @@ import pytest import tempfile import shutil import glob +import platform from tests.lib.db_handler import DBHandler from tests.lib.file_handler import RemoteFileHandler @@ -58,7 +59,8 @@ class ModuleUnitTest(BaseTest): m.undo() @pytest.fixture(scope="module") - def download_test_data(self, test_data_folder): + def download_test_data(self, test_data_folder, persist=False): + test_data_folder = test_data_folder or self.TEST_DATA_FOLDER if test_data_folder: print("Using existing folder {}".format(test_data_folder)) yield test_data_folder @@ -78,7 +80,8 @@ class ModuleUnitTest(BaseTest): print("Temporary folder created:: {}".format(tmpdir)) yield tmpdir - if not self.PERSIST: + persist = persist or self.PERSIST + if not persist: print("Removing {}".format(tmpdir)) shutil.rmtree(tmpdir) @@ -188,14 +191,28 @@ class PublishTest(ModuleUnitTest): """ APP = "" - APP_VARIANT = "" # keep empty to locate latest installed variant TIMEOUT = 120 # publish timeout - @property - def app_name(self): - if self.APP_VARIANT: - return "{}/{}".format(self.APP, self.APP_VARIANT) + # could be overwritten by command line arguments + # command line value takes precedence + + # keep empty to locate latest installed variant or explicit + APP_VARIANT = "" + PERSIST = True # True - keep test_db, test_openpype, outputted test files + TEST_DATA_FOLDER = None # use specific folder of unzipped test file + + @pytest.fixture(scope="module") + def app_name(self, app_variant): + """Returns calculated value for ApplicationManager. Eg.(nuke/12-2)""" + from openpype.lib import ApplicationManager + app_variant = app_variant or self.APP_VARIANT + + application_manager = ApplicationManager() + if not app_variant: + app_variant = find_variant_key(application_manager, self.APP) + + yield "{}/{}".format(self.APP, app_variant) @pytest.fixture(scope="module") def last_workfile_path(self, download_test_data): @@ -203,6 +220,7 @@ class PublishTest(ModuleUnitTest): @pytest.fixture(scope="module") def startup_scripts(self, monkeypatch_session, download_test_data): + """"Adds init scripts (like userSetup) to expected location""" raise NotImplementedError @pytest.fixture(scope="module") @@ -270,12 +288,6 @@ class PublishTest(ModuleUnitTest): if app_args: data["app_args"] = app_args - variant = self.APP_VARIANT - if not variant: - variant = find_variant_key(application_manager, self.APP) - - app_name = "{}/{}".format(self.APP, variant) - app_process = application_manager.launch(app_name, **data) yield app_process @@ -295,13 +307,13 @@ class PublishTest(ModuleUnitTest): yield True def test_folder_structure_same(self, dbcon, publish_finished, - download_test_data): + download_test_data, output_folder_url): """Check if expected and published subfolders contain same files. Compares only presence, not size nor content! """ published_dir_base = download_test_data - published_dir = os.path.join(published_dir_base, + published_dir = os.path.join(output_folder_url, self.PROJECT, self.TASK, "**") @@ -311,7 +323,8 @@ class PublishTest(ModuleUnitTest): self.PROJECT, self.TASK, "**") - + print("Comparing published:'{}' : expected:'{}'".format(published_dir, + expected_dir)) published = set(f.replace(published_dir_base, '') for f in glob.glob(published_dir, recursive=True) if f != published_dir_base and os.path.exists(f))