Forráskód Böngészése

Add parent script path to correctly link pycoverage to pytargets.

Signed-off-by: John <[email protected]>
John 3 éve
szülő
commit
1589819d0b

+ 30 - 11
AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.cpp

@@ -6,14 +6,17 @@
  *
  */
 
+#include <PythonCoverageEditorSystemComponent.h>
+
 #include <AzCore/IO/Path/Path.h>
 #include <AzCore/JSON/document.h>
 #include <AzCore/Module/ModuleManagerBus.h>
 #include <AzCore/Module/Module.h>
 #include <AzCore/Module/DynamicModuleHandle.h>
 #include <AzCore/Serialization/SerializeContext.h>
+#include <AzCore/std/string/regex.h>
 
-#include <PythonCoverageEditorSystemComponent.h>
+#pragma optimize("", off)
 
 namespace PythonCoverage
 {
@@ -109,11 +112,6 @@ namespace PythonCoverage
         const AZ::IO::Path artifactRelativeDir = tempConfig["relative_paths"]["artifact_dir"].GetString();
         m_coverageDir = tempWorkspaceRootDir / artifactRelativeDir;
 
-        // Placeholder name to use for when the test case isn't specified
-        const auto& pythonArtifactCoverageConfig = configurationFile["python"]["artifact"]["coverage"];
-        m_placeholderTestCase = AZStd::string(pythonArtifactCoverageConfig["fixture_placeholder"].GetString()) + "." +
-            AZStd::string(pythonArtifactCoverageConfig["test_case_placeholder"].GetString());
-
         // Everything is good to go, await the first python test case
         m_coverageState = CoverageState::Idle;
         return m_coverageState;
@@ -130,7 +128,9 @@ namespace PythonCoverage
             return;
         }
 
-        contents = testCase + "\n";
+        contents = m_parentScriptPath + "\n";
+        contents += m_testFixture + "\n";
+        contents = m_testCase + "\n";
         contents += m_scriptPath + "\n";
         for (const auto& coveringModule : coveringModules)
         {
@@ -219,19 +219,38 @@ namespace PythonCoverage
             WriteCoverageFile();
             m_coverageState = CoverageState::Idle;
         }
-        
+
         if (testCase.empty())
         {
             // We need to be able to pinpoint the coverage data to the specific test case names otherwise we will not be able
             // to specify which specific tests should be run in the future (filename does not necessarily equate to test case name)
-            AZ_Warning(LogCallSite, false, "No test case specified, placeholder test case name will be used for this test");
-            m_testCase = m_placeholderTestCase;
+            AZ_Error(LogCallSite, false, "No test case specified, coverage data gathering will be disabled for this test");
+            return;
+        }
+
+        const auto matcherPattern = AZStd::regex("(.*)::(.*)::(.*)");
+        const auto strTestCase = AZStd::string(testCase);
+        AZStd::smatch testCaseMatches;
+        if (!AZStd::regex_search(strTestCase, testCaseMatches, matcherPattern))
+        {
+            AZ_Error(
+                LogCallSite,
+                false,
+                "The test case name '%s' did not comply to the format expected by the coverage gem "
+                "'parent_script_path::fixture_name::test_case_name', coverage data gathering will be disabled for this test",
+                strTestCase.c_str());
+            return;
         }
 
+        m_parentScriptPath = testCaseMatches[1];
+        m_testFixture = testCaseMatches[2];
+        m_testCase = testCaseMatches[3];
         m_entityComponents.clear();
         m_scriptPath = filename;
-        const auto coverageFile = m_coverageDir / AZStd::string::format("%.*s.pycoverage", AZ_STRING_ARG(testCase));
+        const auto coverageFile = m_coverageDir / AZStd::string::format("%.*s.pycoverage", m_testCase);
         m_coverageFile = coverageFile;
         m_coverageState = CoverageState::Gathering;
     }
 } // namespace PythonCoverage
+
+#pragma optimize("", on)

+ 3 - 1
AutomatedTesting/Gem/PythonCoverage/Code/Source/PythonCoverageEditorSystemComponent.h

@@ -80,7 +80,9 @@ namespace PythonCoverage
         AZ::IO::Path m_coverageDir; //!< Directory to write coverage data to.
         AZ::IO::Path m_coverageFile; //!< Full file path to write coverage data to.
         AZStd::string m_scriptPath; //!< Path to the Python test script being executed.
+        AZStd::string m_parentScriptPath; //!< Path to the parent Python script all test case siblings belong
+                                          //!< to (used to ID the python test target).
+        AZStd::string m_testFixture; //!< Name of the test fixture this test case belongs to.
         AZStd::string m_testCase; //!< Name of current test case that coverage data is being gathered for.
-        AZStd::string m_placeholderTestCase; //!< Placeholder name to use when the test case isn't specified.
     };
 } // namespace PythonCoverage

+ 2 - 2
cmake/TestImpactFramework/ConsoleFrontendConfig.in

@@ -98,11 +98,11 @@
     }
   },
   "python": {
-    "artifact" {
+    "artifact": {  
       "coverage": {
         "fixture_placeholder": "PlaceholderFixture",
         "test_case_placeholder": "PlaceholderTestCase"
       }
-    },
+    }
   }
 }