Skip to content

Commit 20e0bd9

Browse files
committed
switch to using absolute paths for unittest classes with pytest
1 parent dbcc69d commit 20e0bd9

File tree

2 files changed

+70
-18
lines changed

2 files changed

+70
-18
lines changed

python_files/tests/pytestadapter/expected_discovery_test_output.py

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@
9191
),
9292
}
9393
],
94-
"id_": "unittest_pytest_same_file.py::TestExample",
94+
"id_": get_absolute_test_id(
95+
"unittest_pytest_same_file.py::TestExample",
96+
os.fspath(unit_pytest_same_file_path),
97+
),
9598
},
9699
{
97100
"name": "test_true_pytest",
@@ -200,7 +203,10 @@
200203
),
201204
},
202205
],
203-
"id_": "unittest_folder/test_add.py::TestAddFunction",
206+
"id_": get_absolute_test_id(
207+
"unittest_folder/test_add.py::TestAddFunction",
208+
os.fspath(test_add_path),
209+
),
204210
},
205211
{
206212
"name": "TestDuplicateFunction",
@@ -225,7 +231,10 @@
225231
),
226232
},
227233
],
228-
"id_": "unittest_folder/test_add.py::TestDuplicateFunction",
234+
"id_": get_absolute_test_id(
235+
"unittest_folder/test_add.py::TestDuplicateFunction",
236+
os.fspath(test_add_path),
237+
),
229238
},
230239
],
231240
},
@@ -275,7 +284,10 @@
275284
),
276285
},
277286
],
278-
"id_": "unittest_folder/test_subtract.py::TestSubtractFunction",
287+
"id_": get_absolute_test_id(
288+
"unittest_folder/test_subtract.py::TestSubtractFunction",
289+
os.fspath(test_subtract_path),
290+
),
279291
},
280292
{
281293
"name": "TestDuplicateFunction",
@@ -300,7 +312,10 @@
300312
),
301313
},
302314
],
303-
"id_": "unittest_folder/test_subtract.py::TestDuplicateFunction",
315+
"id_": get_absolute_test_id(
316+
"unittest_folder/test_subtract.py::TestDuplicateFunction",
317+
test_subtract_path,
318+
),
304319
},
305320
],
306321
},
@@ -534,7 +549,10 @@
534549
"name": "TestClass",
535550
"path": os.fspath(parameterize_tests_path),
536551
"type_": "class",
537-
"id_": "parametrize_tests.py::TestClass",
552+
"id_": get_absolute_test_id(
553+
"parametrize_tests.py::TestClass",
554+
parameterize_tests_path,
555+
),
538556
"children": [
539557
{
540558
"name": "test_adding",
@@ -907,13 +925,19 @@
907925
"name": "TestFirstClass",
908926
"path": str(TEST_MULTI_CLASS_NEST_PATH),
909927
"type_": "class",
910-
"id_": "test_multi_class_nest.py::TestFirstClass",
928+
"id_": get_absolute_test_id(
929+
"test_multi_class_nest.py::TestFirstClass",
930+
TEST_MULTI_CLASS_NEST_PATH,
931+
),
911932
"children": [
912933
{
913934
"name": "TestSecondClass",
914935
"path": str(TEST_MULTI_CLASS_NEST_PATH),
915936
"type_": "class",
916-
"id_": "test_multi_class_nest.py::TestFirstClass::TestSecondClass",
937+
"id_": get_absolute_test_id(
938+
"test_multi_class_nest.py::TestFirstClass::TestSecondClass",
939+
TEST_MULTI_CLASS_NEST_PATH,
940+
),
917941
"children": [
918942
{
919943
"name": "test_second",
@@ -954,7 +978,10 @@
954978
"name": "TestSecondClass2",
955979
"path": str(TEST_MULTI_CLASS_NEST_PATH),
956980
"type_": "class",
957-
"id_": "test_multi_class_nest.py::TestFirstClass::TestSecondClass2",
981+
"id_": get_absolute_test_id(
982+
"test_multi_class_nest.py::TestFirstClass::TestSecondClass2",
983+
TEST_MULTI_CLASS_NEST_PATH,
984+
),
958985
"children": [
959986
{
960987
"name": "test_second2",
@@ -1196,7 +1223,10 @@
11961223
+ "::TestNotEmpty::test_string",
11971224
},
11981225
],
1199-
"id_": "same_function_new_class_param.py::TestNotEmpty",
1226+
"id_": get_absolute_test_id(
1227+
"same_function_new_class_param.py::TestNotEmpty",
1228+
TEST_DATA_PATH / "same_function_new_class_param.py",
1229+
),
12001230
},
12011231
{
12021232
"name": "TestEmpty",
@@ -1264,7 +1294,10 @@
12641294
+ "::TestEmpty::test_string",
12651295
},
12661296
],
1267-
"id_": "same_function_new_class_param.py::TestEmpty",
1297+
"id_": get_absolute_test_id(
1298+
"same_function_new_class_param.py::TestEmpty",
1299+
TEST_DATA_PATH / "same_function_new_class_param.py",
1300+
),
12681301
},
12691302
],
12701303
}
@@ -1334,7 +1367,10 @@
13341367
),
13351368
}
13361369
],
1337-
"id_": "test_param_span_class.py::TestClass1",
1370+
"id_": get_absolute_test_id(
1371+
"test_param_span_class.py::TestClass1",
1372+
TEST_DATA_PATH / "test_param_span_class.py",
1373+
),
13381374
},
13391375
{
13401376
"name": "TestClass2",
@@ -1387,7 +1423,10 @@
13871423
),
13881424
}
13891425
],
1390-
"id_": "test_param_span_class.py::TestClass2",
1426+
"id_": get_absolute_test_id(
1427+
"test_param_span_class.py::TestClass2",
1428+
TEST_DATA_PATH / "test_param_span_class.py",
1429+
),
13911430
},
13921431
],
13931432
}
@@ -1460,7 +1499,10 @@
14601499
),
14611500
},
14621501
],
1463-
"id_": "pytest_describe_plugin/describe_only.py::describe_A",
1502+
"id_": get_absolute_test_id(
1503+
"pytest_describe_plugin/describe_only.py::describe_A",
1504+
describe_only_path,
1505+
),
14641506
}
14651507
],
14661508
}
@@ -1540,7 +1582,10 @@
15401582
),
15411583
},
15421584
],
1543-
"id_": "pytest_describe_plugin/nested_describe.py::describe_list::describe_append",
1585+
"id_": get_absolute_test_id(
1586+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_append",
1587+
nested_describe_path,
1588+
),
15441589
},
15451590
{
15461591
"name": "describe_remove",
@@ -1565,10 +1610,16 @@
15651610
),
15661611
}
15671612
],
1568-
"id_": "pytest_describe_plugin/nested_describe.py::describe_list::describe_remove",
1613+
"id_": get_absolute_test_id(
1614+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_remove",
1615+
nested_describe_path,
1616+
),
15691617
},
15701618
],
1571-
"id_": "pytest_describe_plugin/nested_describe.py::describe_list",
1619+
"id_": get_absolute_test_id(
1620+
"pytest_describe_plugin/nested_describe.py::describe_list",
1621+
nested_describe_path,
1622+
),
15721623
}
15731624
],
15741625
}

python_files/vscode_pytest/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,13 @@ def create_class_node(class_module: pytest.Class | DescribeBlock) -> TestNode:
764764
Keyword arguments:
765765
class_module -- the pytest object representing a class module.
766766
"""
767+
767768
return {
768769
"name": class_module.name,
769770
"path": get_node_path(class_module),
770771
"type_": "class",
771772
"children": [],
772-
"id_": class_module.nodeid,
773+
"id_": get_absolute_test_id(class_module.nodeid, get_node_path(class_module)),
773774
}
774775

775776

0 commit comments

Comments
 (0)