Skip to content

Commit 7ae5e4e

Browse files
authored
Fixing long class name (#20739)
Updating the discovery phase of python language flow and updated typescript version consumed in the task
1 parent 3224341 commit 7ae5e4e

File tree

16 files changed

+1683
-1441
lines changed

16 files changed

+1683
-1441
lines changed

Diff for: Tasks/AzureTestPlanV0/Invokers/pythoninvoker.ts

+42-47
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,25 @@ export async function executePythonTests(testsToBeExecuted: string[]):Promise<nu
1414

1515
// Extract discovered tests from stdout
1616
const discoveredTests: string[] = extractDiscoveredTests(discoveryResult.stdout ?? '');
17-
testsToBeExecuted = testsToBeExecuted.map(transformTestStrings);
17+
var testStringtoFQNMap: Map<string, string> = new Map<string, string>();
18+
19+
for(let test of discoveredTests){
20+
testStringtoFQNMap.set(transformTestStrings(test), test);
21+
}
22+
23+
var testsToRun: string[] = [];
24+
25+
for(let test of testsToBeExecuted){
26+
if(!testStringtoFQNMap.has(test)){
27+
tl.debug(`Test ${test} not found in discovered tests`);
28+
}
29+
else{
30+
testsToRun.push(testStringtoFQNMap.get(test));
31+
}
32+
}
1833

1934
// Find common tests between testsToBeExecuted and discovered tests
20-
const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);
35+
//const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);
2136

2237
// Variables for debug console logs
2338
const testsToBeExecutedString: string = testsToBeExecuted.join(", ");
@@ -65,41 +80,9 @@ async function runPytestCommand(args: string[]): Promise<SpawnResult> {
6580
}
6681
}
6782

68-
function extractOldDiscoveredTests(output) {
69-
const testNames = [];
70-
let currentPackage = '';
71-
let currentModule = '';
72-
let currentClass = '';
73-
74-
const lines = output.split('\n');
75-
76-
for (let i = 0; i < lines.length; i++) {
77-
const line = lines[i].trim();
78-
79-
if (line.startsWith('<Package')) {
80-
currentPackage = line.match(/<Package (.*?)>/)[1];
81-
} else if (line.startsWith('<Module')) {
82-
currentModule = line.match(/<Module (.*?)>/)[1];
83-
} else if (line.startsWith('<UnitTestCase')) {
84-
currentClass = line.match(/<UnitTestCase (.*?)>/)[1];
85-
} else if (line.startsWith('<TestCaseFunction')) {
86-
const functionName = line.match(/<TestCaseFunction (.*?)>/)[1];
87-
let fullyQualifiedName = '';
88-
if (currentPackage !== '') {
89-
fullyQualifiedName += currentPackage + '/';
90-
}
91-
fullyQualifiedName += `${currentModule}::${currentClass}::${functionName}`;
92-
testNames.push(fullyQualifiedName);
93-
}
94-
}
95-
tl.debug("Discovered tests : " + testNames);
96-
return testNames;
97-
}
98-
99-
function extractDiscoveredTests(output: string) {
100-
const testNames = [];
101-
102-
const lines = output.split('\n');
83+
function extractDiscoveredTests(output: string): string[] {
84+
var testNames: string[] = [];
85+
var lines: string[] = output.split('\n');
10386

10487
for (let i = 0; i < lines.length; i++) {
10588
const line = lines[i].trim();
@@ -111,17 +94,29 @@ function extractDiscoveredTests(output: string) {
11194
return testNames;
11295
}
11396

114-
function transformTestStrings(test: string): string {
97+
// Input is like Folder/SubFolder/TestClass.py::TestSubClass::TestSubSubClass::test_method_name
98+
// Output is lke Folder.SubFolder.TestClass.TestSubClass.TestSubSubClass.test_method_name
99+
function transformTestStrings(automatedTestName: string): string {
115100
// Remove any leading or trailing whitespace
116-
test = test.trim();
101+
automatedTestName = automatedTestName.trim();
102+
let updatedAutomatedTestName: string = automatedTestName;
103+
104+
const index = automatedTestName.indexOf("::");
105+
if(index !== -1) {
106+
let testFilePath = automatedTestName.substring(0, index);
107+
let testMethod = automatedTestName.substring(index + 2);
108+
109+
//Check if testfilePath is a python file
110+
if(testFilePath.endsWith(".py")) {
111+
testFilePath = testFilePath.slice(0, -3).replace(/\//g, '.');
117112

118-
// Replace '.' with '/' for the directory structure
119-
// Replace the last part of the string with '.py'
120-
test = test.replace(/\./g, '/').replace(/\.([^/]+)$/, '.py');
113+
//Do the same replace with :: to . in testMethod
114+
testMethod = testMethod.replace(/::/g, '.');
115+
116+
//Finally generate updatedAutomatedTestName
117+
updatedAutomatedTestName = testFilePath + "." + testMethod;
118+
}
119+
}
121120

122-
// Add the `::` before the test function name
123-
const parts = test.split('/');
124-
const functionName = parts.pop(); // Remove the function name
125-
const testFile = parts.join('/'); // Join back the file path
126-
return `${testFile}.py::${functionName}`; // Format as required
121+
return updatedAutomatedTestName;
127122
}

0 commit comments

Comments
 (0)