File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { parseVsId } from './testController/common/projectUtils';
55export 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 - z A - Z ] [ a - z A - 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+
2437export function idToModuleClassMethod ( id : string ) : string | undefined {
2538 // Split by backslash
2639 const parts = id . split ( '\\' ) ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments