Browse Source

Update PyTyest, custom plugin, and remove unused dependency (#13707)

* Update PyTyest, custom plugin, and remove unused dependency

Signed-off-by: sweeneys <[email protected]>
Kadino 2 năm trước cách đây
mục cha
commit
02f0438ed9

+ 16 - 4
AutomatedTesting/Gem/PythonTests/editor_test_testing/TestSuite_Main.py

@@ -46,12 +46,24 @@ class TestEditorTest:
         for arg in sys.argv:
         for arg in sys.argv:
             if not arg.endswith(".py"):
             if not arg.endswith(".py"):
                 TestEditorTest.args.append(arg)
                 TestEditorTest.args.append(arg)
-        try:
+
+        if "--build-directory" in TestEditorTest.args:
+            # passed as two args, flag and value
             build_dir_arg_index = TestEditorTest.args.index("--build-directory")
             build_dir_arg_index = TestEditorTest.args.index("--build-directory")
-        except ValueError:
-            raise ValueError("Must pass --build-directory argument in order to run this test")
+            TestEditorTest.args[build_dir_arg_index + 1] = os.path.abspath(
+                TestEditorTest.args[build_dir_arg_index + 1])
+        else:
+            # may instead be passed as one arg which includes equals-sign between flag and value
+            build_dir_arg_index = 0
+            for arg in TestEditorTest.args:
+                if arg.startswith("--build-directory"):
+                    first, second = arg.split("=", maxsplit=1)
+                    TestEditorTest.args[build_dir_arg_index] = f'{first}={os.path.abspath(second)}'
+                    break
+                build_dir_arg_index += 1
+        if build_dir_arg_index == len(TestEditorTest.args):
+            raise ValueError(f"Must pass --build-directory argument in order to run this test. Found args: {TestEditorTest.args}")
 
 
-        TestEditorTest.args[build_dir_arg_index+1] = os.path.abspath(TestEditorTest.args[build_dir_arg_index+1])
         TestEditorTest.args.append("-s")
         TestEditorTest.args.append("-s")
         TestEditorTest.path = os.path.dirname(os.path.abspath(__file__))
         TestEditorTest.path = os.path.dirname(os.path.abspath(__file__))
         cls._asset_processor = None
         cls._asset_processor = None

+ 6 - 8
Tools/LyTestTools/ly_test_tools/o3de/multi_test_framework.py

@@ -532,12 +532,9 @@ class MultiTestSuite(object):
             runners.append(self._create_runner("run_parallel_batched_tests", cls._run_parallel_batched_tests,
             runners.append(self._create_runner("run_parallel_batched_tests", cls._run_parallel_batched_tests,
                                                parallel_batched_tests, cls))
                                                parallel_batched_tests, cls))
 
 
-            # Now that we have added the functions to the class, have pytest retrieve all the tests the class contains
-            pytest_class_instance = super().collect()[0]
-
-            # Override the istestfunction for the object, with this we make sure that the
-            # runners are always collected, even if they don't follow the "test_" naming
-            original_istestfunction = pytest_class_instance.istestfunction
+            # Override istestfunction for our own object, to collect runners even if they don't follow "test_" naming
+            # avoid declaring istestfunction on the class, so it only exists now after initial pytest collect() has run
+            original_istestfunction = self.istestfunction
 
 
             def istestfunction(self, obj, name):
             def istestfunction(self, obj, name):
                 ret = original_istestfunction(obj, name)
                 ret = original_istestfunction(obj, name)
@@ -545,9 +542,10 @@ class MultiTestSuite(object):
                     ret = hasattr(obj, "marks")
                     ret = hasattr(obj, "marks")
                 return ret
                 return ret
 
 
-            pytest_class_instance.istestfunction = types.MethodType(istestfunction, pytest_class_instance)
-            collection = pytest_class_instance.collect()
+            self.istestfunction = types.MethodType(istestfunction, self)
 
 
+            # Now that we have added the functions to the class, have pytest retrieve all the tests the class contains
+            collection = super().collect()
             collected_run_pytestfuncs = [item for item in collection if
             collected_run_pytestfuncs = [item for item in collection if
                                          # Gets function run type
                                          # Gets function run type
                                          getattr(item.obj, "marks", {}).setdefault("run_type", None) == "run_shared"]
                                          getattr(item.obj, "marks", {}).setdefault("run_type", None) == "run_shared"]

+ 1 - 1
Tools/LyTestTools/setup.py

@@ -35,7 +35,7 @@ if __name__ == '__main__':
             'pluggy',
             'pluggy',
             'psutil',
             'psutil',
             'pyscreenshot',
             'pyscreenshot',
-            'pytest',
+            'pytest>=7.2.0',
             'pytest-mock',
             'pytest-mock',
             'pytest-timeout',
             'pytest-timeout',
             'six',
             'six',

+ 5 - 1
Tools/LyTestTools/tests/integ/__init__.py

@@ -1,6 +1,10 @@
-"""
+r"""
 Copyright (c) Contributors to the Open 3D Engine Project.
 Copyright (c) Contributors to the Open 3D Engine Project.
 For complete copyright and license terms please see the LICENSE at the root of this distribution.
 For complete copyright and license terms please see the LICENSE at the root of this distribution.
 
 
 SPDX-License-Identifier: Apache-2.0 OR MIT
 SPDX-License-Identifier: Apache-2.0 OR MIT
+
+Tests in this directory require setting the `build-directory` parameter, examples:
+python -m pytest --build-directory="c:\git\o3de\build\bin\profile"
+python -m pytest --build-directory="~/git/o3de/build/bin/profile"
 """
 """

+ 2 - 7
Tools/LyTestTools/tests/unit/test_o3de_multi_test_framework.py

@@ -1197,9 +1197,7 @@ class TestMultiTestCollector(unittest.TestCase):
         mock_run.obj.marks = {"run_type": 'run_shared'}
         mock_run.obj.marks = {"run_type": 'run_shared'}
         mock_run_2 = mock.MagicMock()
         mock_run_2 = mock.MagicMock()
         mock_run_2.obj.marks = {"run_type": 'result'}
         mock_run_2.obj.marks = {"run_type": 'result'}
-        mock_instance = mock.MagicMock()
-        mock_instance.collect.return_value = [mock_run, mock_run_2]
-        mock_collect.return_value = [mock_instance]
+        mock_collect.return_value = [mock_run_2]
 
 
         collection = self.mock_test_class.collect()
         collection = self.mock_test_class.collect()
         assert collection == [mock_run_2]
         assert collection == [mock_run_2]
@@ -1222,13 +1220,10 @@ class TestMultiTestCollector(unittest.TestCase):
         mock_run_2 = mock.MagicMock()
         mock_run_2 = mock.MagicMock()
         mock_run_2.obj.marks = {"run_type": 'result'}
         mock_run_2.obj.marks = {"run_type": 'result'}
         mock_run_2.function.marks = {"runner": mock_runner_2}
         mock_run_2.function.marks = {"runner": mock_runner_2}
-        mock_instance = mock.MagicMock()
-        mock_instance.collect.return_value = [mock_run, mock_run_2]
-        mock_collect.return_value = [mock_instance]
+        mock_collect.return_value = [mock_run_2]
 
 
         self.mock_test_class.collect()
         self.mock_test_class.collect()
 
 
-        assert mock_runner.run_pytestfunc == mock_run
         assert mock_run_2 in mock_runner_2.result_pytestfuncs
         assert mock_run_2 in mock_runner_2.result_pytestfuncs
 
 
     @mock.patch('ly_test_tools.o3de.multi_test_framework.isinstance', mock.MagicMock())
     @mock.patch('ly_test_tools.o3de.multi_test_framework.isinstance', mock.MagicMock())

+ 4 - 7
python/requirements.txt

@@ -39,6 +39,8 @@ easyprocess==0.2.8 \
     --hash=sha256:da7f67a006e2eb63d86a8f3f4baa9d6752dab9676009a67193a4e433f2f41c2a \
     --hash=sha256:da7f67a006e2eb63d86a8f3f4baa9d6752dab9676009a67193a4e433f2f41c2a \
     --hash=sha256:e8258e8fafddc97a9780bafa83a0b7a7223e3679478ebc7a64cb320d434354e5 \
     --hash=sha256:e8258e8fafddc97a9780bafa83a0b7a7223e3679478ebc7a64cb320d434354e5 \
     # via pyscreenshot
     # via pyscreenshot
+exceptiongroup==1.0.4 \
+    --hash=sha256:542adf9dea4055530d6e1279602fa5cb11dab2395fa650b8674eaec35fc4a828
 gitdb2==2.0.6 \
 gitdb2==2.0.6 \
     --hash=sha256:1b6df1433567a51a4a9c1a5a0de977aa351a405cc56d7d35f3388bad1f630350 \
     --hash=sha256:1b6df1433567a51a4a9c1a5a0de977aa351a405cc56d7d35f3388bad1f630350 \
     --hash=sha256:96bbb507d765a7f51eb802554a9cfe194a174582f772e0d89f4e87288c288b7b \
     --hash=sha256:96bbb507d765a7f51eb802554a9cfe194a174582f772e0d89f4e87288c288b7b \
@@ -219,10 +221,6 @@ psutil==5.8.0 \
     --hash=sha256:f4634b033faf0d968bb9220dd1c793b897ab7f1189956e1aa9eae752527127d3 \
     --hash=sha256:f4634b033faf0d968bb9220dd1c793b897ab7f1189956e1aa9eae752527127d3 \
     --hash=sha256:fcc01e900c1d7bee2a37e5d6e4f9194760a93597c97fee89c4ae51701de03563
     --hash=sha256:fcc01e900c1d7bee2a37e5d6e4f9194760a93597c97fee89c4ae51701de03563
     # via requirements.txt
     # via requirements.txt
-py==1.11.0 \
-    --hash=sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719 \
-    --hash=sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378 \
-    # via -r requirements.txt
 pyparsing==2.4.7 \
 pyparsing==2.4.7 \
     --hash=sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1 \
     --hash=sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1 \
     --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \
     --hash=sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b \
@@ -239,9 +237,8 @@ pytest-timeout==2.1.0 \
     --hash=sha256:c07ca07404c612f8abbe22294b23c368e2e5104b521c1790195561f37e1ac3d9 \
     --hash=sha256:c07ca07404c612f8abbe22294b23c368e2e5104b521c1790195561f37e1ac3d9 \
     --hash=sha256:f6f50101443ce70ad325ceb4473c4255e9d74e3c7cd0ef827309dfa4c0d975c6
     --hash=sha256:f6f50101443ce70ad325ceb4473c4255e9d74e3c7cd0ef827309dfa4c0d975c6
     # via requirements.txt
     # via requirements.txt
-pytest==6.2.5 \
-    --hash=sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89 \
-    --hash=sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134
+pytest==7.2.0 \
+    --hash=sha256:892f933d339f068883b6fd5a459f03d85bfcb355e4981e146d2c7616c21fef71
     # via requirements.txt, pytest-mock, pytest-timeout
     # via requirements.txt, pytest-mock, pytest-timeout
 python-dateutil==2.8.1 \
 python-dateutil==2.8.1 \
     --hash=sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c \
     --hash=sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c \