Skip to content

Commit 3c93673

Browse files
authored
Changes for executing Python Tests (#20716)
1 parent 478b013 commit 3c93673

File tree

10 files changed

+136
-22
lines changed

10 files changed

+136
-22
lines changed

Tasks/AzureTestPlanV0/Invokers/pythoninvoker.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import constants = require('../constants');
44

55
export async function executePythonTests(testsToBeExecuted: string[]):Promise<number> {
66
// Perform test discovery
7-
const discoveryArgs: string[] = ['--collect-only'];
7+
const discoveryArgs: string[] = ['--collect-only', '-q'];
88
const discoveryResult = await runPytestCommand(discoveryArgs);
99

1010
if (discoveryResult.status !== 0) {
@@ -14,10 +14,18 @@ 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);
1718

1819
// Find common tests between testsToBeExecuted and discovered tests
1920
const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);
2021

22+
// Variables for debug console logs
23+
const testsToBeExecutedString: string = testsToBeExecuted.join(", ");
24+
const testsToRunString: string = testsToRun.join(", ");
25+
26+
tl.debug(`Tests to executed are: ${testsToBeExecutedString}`);
27+
tl.debug(`Tests to run are: ${testsToRunString}`);
28+
2129
if (testsToRun.length === 0) {
2230
tl.warning("No common tests found between specified tests and discovered tests.");
2331
return 0;
@@ -57,7 +65,7 @@ async function runPytestCommand(args: string[]): Promise<SpawnResult> {
5765
}
5866
}
5967

60-
function extractDiscoveredTests(output) {
68+
function extractOldDiscoveredTests(output) {
6169
const testNames = [];
6270
let currentPackage = '';
6371
let currentModule = '';
@@ -87,3 +95,33 @@ function extractDiscoveredTests(output) {
8795
tl.debug("Discovered tests : " + testNames);
8896
return testNames;
8997
}
98+
99+
function extractDiscoveredTests(output: string) {
100+
const testNames = [];
101+
102+
const lines = output.split('\n');
103+
104+
for (let i = 0; i < lines.length; i++) {
105+
const line = lines[i].trim();
106+
if(line && line.includes(".py")){
107+
testNames.push(line);
108+
}
109+
}
110+
tl.debug("Discovered tests : " + testNames);
111+
return testNames;
112+
}
113+
114+
function transformTestStrings(test: string): string {
115+
// Remove any leading or trailing whitespace
116+
test = test.trim();
117+
118+
// Replace '.' with '/' for the directory structure
119+
// Replace the last part of the string with '.py'
120+
test = test.replace(/\./g, '/').replace(/\.([^/]+)$/, '.py');
121+
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
127+
}

Tasks/AzureTestPlanV0/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 250,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"preview": true,
2020
"demands": [],

Tasks/AzureTestPlanV0/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 250,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"preview": true,
2020
"demands": [],
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Default|0.250.2
2-
Node20-225|0.250.3
1+
Default|0.250.4
2+
Node20-225|0.250.5

_generated/AzureTestPlanV0/Invokers/pythoninvoker.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import constants = require('../constants');
44

55
export async function executePythonTests(testsToBeExecuted: string[]):Promise<number> {
66
// Perform test discovery
7-
const discoveryArgs: string[] = ['--collect-only'];
7+
const discoveryArgs: string[] = ['--collect-only', '-q'];
88
const discoveryResult = await runPytestCommand(discoveryArgs);
99

1010
if (discoveryResult.status !== 0) {
@@ -14,10 +14,18 @@ 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);
1718

1819
// Find common tests between testsToBeExecuted and discovered tests
1920
const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);
2021

22+
// Variables for debug console logs
23+
const testsToBeExecutedString: string = testsToBeExecuted.join(", ");
24+
const testsToRunString: string = testsToRun.join(", ");
25+
26+
tl.debug(`Tests to executed are: ${testsToBeExecutedString}`);
27+
tl.debug(`Tests to run are: ${testsToRunString}`);
28+
2129
if (testsToRun.length === 0) {
2230
tl.warning("No common tests found between specified tests and discovered tests.");
2331
return 0;
@@ -57,7 +65,7 @@ async function runPytestCommand(args: string[]): Promise<SpawnResult> {
5765
}
5866
}
5967

60-
function extractDiscoveredTests(output) {
68+
function extractOldDiscoveredTests(output) {
6169
const testNames = [];
6270
let currentPackage = '';
6371
let currentModule = '';
@@ -87,3 +95,33 @@ function extractDiscoveredTests(output) {
8795
tl.debug("Discovered tests : " + testNames);
8896
return testNames;
8997
}
98+
99+
function extractDiscoveredTests(output: string) {
100+
const testNames = [];
101+
102+
const lines = output.split('\n');
103+
104+
for (let i = 0; i < lines.length; i++) {
105+
const line = lines[i].trim();
106+
if(line && line.includes(".py")){
107+
testNames.push(line);
108+
}
109+
}
110+
tl.debug("Discovered tests : " + testNames);
111+
return testNames;
112+
}
113+
114+
function transformTestStrings(test: string): string {
115+
// Remove any leading or trailing whitespace
116+
test = test.trim();
117+
118+
// Replace '.' with '/' for the directory structure
119+
// Replace the last part of the string with '.py'
120+
test = test.replace(/\./g, '/').replace(/\.([^/]+)$/, '.py');
121+
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
127+
}

_generated/AzureTestPlanV0/task.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 250,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -186,8 +186,8 @@
186186
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
187187
},
188188
"_buildConfigMapping": {
189-
"Default": "0.250.2",
189+
"Default": "0.250.4",
190190
"LocalPackages": "0.249.4",
191-
"Node20-225": "0.250.3"
191+
"Node20-225": "0.250.5"
192192
}
193193
}

_generated/AzureTestPlanV0/task.loc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 250,
17-
"Patch": 2
17+
"Patch": 4
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -186,8 +186,8 @@
186186
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
187187
},
188188
"_buildConfigMapping": {
189-
"Default": "0.250.2",
189+
"Default": "0.250.4",
190190
"LocalPackages": "0.249.4",
191-
"Node20-225": "0.250.3"
191+
"Node20-225": "0.250.5"
192192
}
193193
}

_generated/AzureTestPlanV0_Node20/Invokers/pythoninvoker.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import constants = require('../constants');
44

55
export async function executePythonTests(testsToBeExecuted: string[]):Promise<number> {
66
// Perform test discovery
7-
const discoveryArgs: string[] = ['--collect-only'];
7+
const discoveryArgs: string[] = ['--collect-only', '-q'];
88
const discoveryResult = await runPytestCommand(discoveryArgs);
99

1010
if (discoveryResult.status !== 0) {
@@ -14,10 +14,18 @@ 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);
1718

1819
// Find common tests between testsToBeExecuted and discovered tests
1920
const testsToRun: string[] = testsToBeExecuted.filter(test => discoveredTests.indexOf(test) !== -1);
2021

22+
// Variables for debug console logs
23+
const testsToBeExecutedString: string = testsToBeExecuted.join(", ");
24+
const testsToRunString: string = testsToRun.join(", ");
25+
26+
tl.debug(`Tests to executed are: ${testsToBeExecutedString}`);
27+
tl.debug(`Tests to run are: ${testsToRunString}`);
28+
2129
if (testsToRun.length === 0) {
2230
tl.warning("No common tests found between specified tests and discovered tests.");
2331
return 0;
@@ -57,7 +65,7 @@ async function runPytestCommand(args: string[]): Promise<SpawnResult> {
5765
}
5866
}
5967

60-
function extractDiscoveredTests(output) {
68+
function extractOldDiscoveredTests(output) {
6169
const testNames = [];
6270
let currentPackage = '';
6371
let currentModule = '';
@@ -87,3 +95,33 @@ function extractDiscoveredTests(output) {
8795
tl.debug("Discovered tests : " + testNames);
8896
return testNames;
8997
}
98+
99+
function extractDiscoveredTests(output: string) {
100+
const testNames = [];
101+
102+
const lines = output.split('\n');
103+
104+
for (let i = 0; i < lines.length; i++) {
105+
const line = lines[i].trim();
106+
if(line && line.includes(".py")){
107+
testNames.push(line);
108+
}
109+
}
110+
tl.debug("Discovered tests : " + testNames);
111+
return testNames;
112+
}
113+
114+
function transformTestStrings(test: string): string {
115+
// Remove any leading or trailing whitespace
116+
test = test.trim();
117+
118+
// Replace '.' with '/' for the directory structure
119+
// Replace the last part of the string with '.py'
120+
test = test.replace(/\./g, '/').replace(/\.([^/]+)$/, '.py');
121+
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
127+
}

_generated/AzureTestPlanV0_Node20/task.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 250,
17-
"Patch": 3
17+
"Patch": 5
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -190,8 +190,8 @@
190190
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
191191
},
192192
"_buildConfigMapping": {
193-
"Default": "0.250.2",
193+
"Default": "0.250.4",
194194
"LocalPackages": "0.249.4",
195-
"Node20-225": "0.250.3"
195+
"Node20-225": "0.250.5"
196196
}
197197
}

_generated/AzureTestPlanV0_Node20/task.loc.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 250,
17-
"Patch": 3
17+
"Patch": 5
1818
},
1919
"preview": true,
2020
"demands": [],
@@ -190,8 +190,8 @@
190190
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
191191
},
192192
"_buildConfigMapping": {
193-
"Default": "0.250.2",
193+
"Default": "0.250.4",
194194
"LocalPackages": "0.249.4",
195-
"Node20-225": "0.250.3"
195+
"Node20-225": "0.250.5"
196196
}
197197
}

0 commit comments

Comments
 (0)