From d55d996f9c58030c86de4eb158837ea289d834d4 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 3 Dec 2021 15:39:43 +0100 Subject: [PATCH] OP-2042 - added functionality to reuse existing folder for testdata --- .../hosts/nuke/test_publish_in_nuke.py | 16 +++------ tests/lib/testing_classes.py | 34 +++++++++++-------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/tests/integration/hosts/nuke/test_publish_in_nuke.py b/tests/integration/hosts/nuke/test_publish_in_nuke.py index 6dc880d757..483e9fef98 100644 --- a/tests/integration/hosts/nuke/test_publish_in_nuke.py +++ b/tests/integration/hosts/nuke/test_publish_in_nuke.py @@ -25,7 +25,7 @@ class TestPublishInNuke(PublishTest): {OPENPYPE_ROOT}/.venv/Scripts/python.exe {OPENPYPE_ROOT}/start.py runtests ../tests/integration/hosts/nuke # noqa: E501 """ - PERSIST = True # True - keep test_db, test_openpype, outputted test files + PERSIST = False # True - keep test_db, test_openpype, outputted test files TEST_FILES = [ ("1SUurHj2aiQ21ZIMJfGVBI2KjR8kIjBGI", "test_Nuke_publish.zip", "") @@ -38,11 +38,12 @@ class TestPublishInNuke(PublishTest): TIMEOUT = 120 # publish timeout + TEST_DATA_FOLDER = None # provide existing folder with test data + @pytest.fixture(scope="module") def last_workfile_path(self, download_test_data): """Get last_workfile_path from source data. - Maya expects workfile in proper folder, so copy is done first. """ log.info("log last_workfile_path") src_path = os.path.join( @@ -50,17 +51,8 @@ class TestPublishInNuke(PublishTest): "input", "workfile", "test_project_test_asset_CompositingInNuke_v001.nk") - dest_folder = os.path.join(download_test_data, - self.PROJECT, - self.ASSET, - "work", - self.TASK) - os.makedirs(dest_folder) - dest_path = os.path.join( - dest_folder, "test_project_test_asset_CompositingInNuke_v001.nk") - shutil.copy(src_path, dest_path) - yield dest_path + yield src_path @pytest.fixture(scope="module") def startup_scripts(self, monkeypatch_session, download_test_data): diff --git a/tests/lib/testing_classes.py b/tests/lib/testing_classes.py index 59d4abb3aa..aa8ef3caab 100644 --- a/tests/lib/testing_classes.py +++ b/tests/lib/testing_classes.py @@ -45,6 +45,8 @@ class ModuleUnitTest(BaseTest): ASSET = "test_asset" TASK = "test_task" + TEST_DATA_FOLDER = None + @pytest.fixture(scope='session') def monkeypatch_session(self): """Monkeypatch couldn't be used with module or session fixtures.""" @@ -55,24 +57,28 @@ class ModuleUnitTest(BaseTest): @pytest.fixture(scope="module") def download_test_data(self): - tmpdir = tempfile.mkdtemp() - for test_file in self.TEST_FILES: - file_id, file_name, md5 = test_file + if self.TEST_DATA_FOLDER: + print("Using existing folder {}".format(self.TEST_DATA_FOLDER)) + yield self.TEST_DATA_FOLDER + else: + tmpdir = tempfile.mkdtemp() + for test_file in self.TEST_FILES: + file_id, file_name, md5 = test_file - f_name, ext = os.path.splitext(file_name) + f_name, ext = os.path.splitext(file_name) - RemoteFileHandler.download_file_from_google_drive(file_id, - str(tmpdir), - file_name) + RemoteFileHandler.download_file_from_google_drive(file_id, + str(tmpdir), + file_name) - if ext.lstrip('.') in RemoteFileHandler.IMPLEMENTED_ZIP_FORMATS: - RemoteFileHandler.unzip(os.path.join(tmpdir, file_name)) - print("Temporary folder created:: {}".format(tmpdir)) - yield tmpdir + if ext.lstrip('.') in RemoteFileHandler.IMPLEMENTED_ZIP_FORMATS: #noqa E501 + RemoteFileHandler.unzip(os.path.join(tmpdir, file_name)) + print("Temporary folder created:: {}".format(tmpdir)) + yield tmpdir - if not self.PERSIST: - print("Removing {}".format(tmpdir)) - shutil.rmtree(tmpdir) + if not self.PERSIST: + print("Removing {}".format(tmpdir)) + shutil.rmtree(tmpdir) @pytest.fixture(scope="module") def env_var(self, monkeypatch_session, download_test_data):