Skip to content

Commit 15cd82d

Browse files
Copilotedvilme
andauthored
Only strip the project prefix when it is a project URI
Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
1 parent 3c0fec2 commit 15cd82d

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎src/client/testing/utils.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { parseVsId } from './testController/common/projectUtils';
55
export async function writeTestIdToClipboard(testItem: TestItem): Promise<void> {
66
if (testItem && typeof testItem.id === 'string') {
77
// Strip the project scope prefix (if any) so only the test id is copied.
8-
const [, testId] = parseVsId(testItem.id);
8+
const testId = stripProjectId(testItem.id);
99
if (testId.includes('\\') && testId.indexOf('::') === -1) {
1010
// Convert the id to a module.class.method format as this is a unittest
1111
const moduleClassMethod = idToModuleClassMethod(testId);
@@ -21,6 +21,19 @@ export async function writeTestIdToClipboard(testItem: TestItem): Promise<void>
2121
}
2222
}
2323

24+
// Project ids are always URIs (see getProjectId), so only strip a prefix that looks
25+
// like one. Otherwise a pytest parameter containing the separator text, such as
26+
// "test_foo.py::test_value[value@@vsc@@suffix]", would be truncated.
27+
const PROJECT_ID_PATTERN = /^[a-zA-Z][a-zA-Z\d+.-]*:\/\//;
28+
29+
function stripProjectId(vsId: string): string {
30+
const [projectId, testId] = parseVsId(vsId);
31+
if (projectId === undefined || !PROJECT_ID_PATTERN.test(projectId)) {
32+
return vsId;
33+
}
34+
return testId;
35+
}
36+
2437
export function idToModuleClassMethod(id: string): string | undefined {
2538
// Split by backslash
2639
const parts = id.split('\\');

‎src/test/testing/utils.unit.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ suite('Testing - utils', () => {
5656
expect(await copiedText(id)).to.equal('tests/unit/test_foo.py::test_pipe_single[False]');
5757
});
5858

59+
test('legacy parameterized pytest id containing the separator text is copied as is', async () => {
60+
const id = `tests/test_foo.py::test_value[value${PROJECT_ID_SEPARATOR}suffix]`;
61+
62+
expect(await copiedText(id)).to.equal(id);
63+
});
64+
65+
test('project scoped parameterized pytest id containing the separator text keeps the parameters', async () => {
66+
const id = `file:///path/to/workspace${PROJECT_ID_SEPARATOR}tests/test_foo.py::test_value[value${PROJECT_ID_SEPARATOR}suffix]`;
67+
68+
expect(await copiedText(id)).to.equal(`tests/test_foo.py::test_value[value${PROJECT_ID_SEPARATOR}suffix]`);
69+
});
70+
5971
test('project scoped windows pytest id drops the project prefix', async () => {
6072
const id = `file:///c%3A/workspace${PROJECT_ID_SEPARATOR}c:\\workspace\\tests\\test_foo.py::test_bar`;
6173

0 commit comments

Comments
 (0)