From 8eb7a30358275f47ca21691dca221fc00f2b4d57 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 3 Dec 2021 17:38:02 +0100 Subject: [PATCH] OP-2042 - added a functionality to inject additional command line arguments --- openpype/lib/applications.py | 2 ++ tests/lib/testing_classes.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index 30be92e886..6eb44a9694 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -716,6 +716,8 @@ class ApplicationLaunchContext: # subprocess.Popen launch arguments (first argument in constructor) self.launch_args = executable.as_args() self.launch_args.extend(application.arguments) + if self.data.get("app_args"): + self.launch_args.extend(self.data.pop("app_args")) # Handle launch environemtns env = self.data.pop("env", None) diff --git a/tests/lib/testing_classes.py b/tests/lib/testing_classes.py index 92b2b2b52b..15ab685739 100644 --- a/tests/lib/testing_classes.py +++ b/tests/lib/testing_classes.py @@ -192,9 +192,35 @@ class PublishTest(ModuleUnitTest): def startup_scripts(self, monkeypatch_session, download_test_data): raise NotImplementedError + @pytest.fixture(scope="module") + def app_args(self, download_test_data): + """Returns additional application arguments from a test file. + + Test zip file should contain file at: + FOLDER_DIR/input/app_args/app_args.json + containing a list of command line arguments (like '-x' etc.) + """ + app_args = [] + args_url = os.path.join(download_test_data, "input", + "app_args", "app_args.json") + if not os.path.exists(args_url): + print("App argument file {} doesn't exist".format(args_url)) + else: + try: + with open(args_url) as json_file: + app_args = json.load(json_file) + + if not isinstance(app_args, list): + raise ValueError + except ValueError: + print("{} doesn't contain valid JSON".format(args_url)) + six.reraise(*sys.exc_info()) + + yield app_args + @pytest.fixture(scope="module") def launched_app(self, dbcon, download_test_data, last_workfile_path, - startup_scripts): + startup_scripts, app_args): """Launch host app""" # set publishing folders root_key = "config.roots.work.{}".format("windows") # TEMP @@ -228,6 +254,8 @@ class PublishTest(ModuleUnitTest): "asset_name": self.ASSET, "task_name": self.TASK } + if app_args: + data["app_args"] = app_args variant = self.APP_VARIANT if not variant: