Skip to content

Commit 757def8

Browse files
Fix unittestadapter test warnings by using different import names for classes that begin with Test, so that pytest doesn't try use them as tests. (microsoft#25732)
When I run the python tests, I get these warnings: This PR fixes these. ``` ========================================================= warnings summary ========================================================= python_files/unittestadapter/pvsc_utils.py:26 /home/gary/dev/vscode-python/python_files/unittestadapter/pvsc_utils.py:26: PytestCollectionWarning: cannot collect test class 'TestNodeTypeEnum' because it has a __new__ constructor (from: tests/unittestadapter/test_discovery.py) class TestNodeTypeEnum(str, enum.Enum): python_files/unittestadapter/pvsc_utils.py:45 /home/gary/dev/vscode-python/python_files/unittestadapter/pvsc_utils.py:45: PytestCollectionWarning: cannot collect test class 'TestNode' because it has a __init__ constructor (from: tests/unittestadapter/test_utils.py) class TestNode(TestData): python_files/unittestadapter/pvsc_utils.py:26 /home/gary/dev/vscode-python/python_files/unittestadapter/pvsc_utils.py:26: PytestCollectionWarning: cannot collect test class 'TestNodeTypeEnum' because it has a __new__ constructor (from: tests/unittestadapter/test_utils.py) class TestNodeTypeEnum(str, enum.Enum): ``` Co-authored-by: Eleanor Boyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent 12bd780 commit 757def8

2 files changed

Lines changed: 45 additions & 44 deletions

File tree

python_files/tests/unittestadapter/test_discovery.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import pytest
1010

1111
from unittestadapter.discovery import discover_tests
12-
from unittestadapter.pvsc_utils import TestNodeTypeEnum, parse_unittest_args
12+
from unittestadapter.pvsc_utils import TestNodeTypeEnum as NodeTypeEnum
13+
from unittestadapter.pvsc_utils import parse_unittest_args
1314

1415
script_dir = pathlib.Path(__file__).parent.parent
1516
sys.path.append(os.fspath(script_dir))
@@ -85,30 +86,30 @@ def test_simple_discovery() -> None:
8586

8687
expected = {
8788
"path": start_dir,
88-
"type_": TestNodeTypeEnum.folder,
89+
"type_": NodeTypeEnum.folder,
8990
"name": ".data",
9091
"children": [
9192
{
9293
"name": "discovery_simple.py",
93-
"type_": TestNodeTypeEnum.file,
94+
"type_": NodeTypeEnum.file,
9495
"path": file_path,
9596
"children": [
9697
{
9798
"name": "DiscoverySimple",
9899
"path": file_path,
99-
"type_": TestNodeTypeEnum.class_,
100+
"type_": NodeTypeEnum.class_,
100101
"children": [
101102
{
102103
"name": "test_one",
103104
"path": file_path,
104-
"type_": TestNodeTypeEnum.test,
105+
"type_": NodeTypeEnum.test,
105106
"lineno": "14",
106107
"id_": file_path + "\\" + "DiscoverySimple" + "\\" + "test_one",
107108
},
108109
{
109110
"name": "test_two",
110111
"path": file_path,
111-
"type_": TestNodeTypeEnum.test,
112+
"type_": NodeTypeEnum.test,
112113
"lineno": "17",
113114
"id_": file_path + "\\" + "DiscoverySimple" + "\\" + "test_two",
114115
},
@@ -137,30 +138,30 @@ def test_simple_discovery_with_top_dir_calculated() -> None:
137138

138139
expected = {
139140
"path": os.fsdecode(pathlib.PurePath(TEST_DATA_PATH)),
140-
"type_": TestNodeTypeEnum.folder,
141+
"type_": NodeTypeEnum.folder,
141142
"name": ".data",
142143
"children": [
143144
{
144145
"name": "discovery_simple.py",
145-
"type_": TestNodeTypeEnum.file,
146+
"type_": NodeTypeEnum.file,
146147
"path": file_path,
147148
"children": [
148149
{
149150
"name": "DiscoverySimple",
150151
"path": file_path,
151-
"type_": TestNodeTypeEnum.class_,
152+
"type_": NodeTypeEnum.class_,
152153
"children": [
153154
{
154155
"name": "test_one",
155156
"path": file_path,
156-
"type_": TestNodeTypeEnum.test,
157+
"type_": NodeTypeEnum.test,
157158
"lineno": "14",
158159
"id_": file_path + "\\" + "DiscoverySimple" + "\\" + "test_one",
159160
},
160161
{
161162
"name": "test_two",
162163
"path": file_path,
163-
"type_": TestNodeTypeEnum.test,
164+
"type_": NodeTypeEnum.test,
164165
"lineno": "17",
165166
"id_": file_path + "\\" + "DiscoverySimple" + "\\" + "test_two",
166167
},
@@ -206,30 +207,30 @@ def test_error_discovery() -> None:
206207

207208
expected = {
208209
"path": start_dir,
209-
"type_": TestNodeTypeEnum.folder,
210+
"type_": NodeTypeEnum.folder,
210211
"name": "discovery_error",
211212
"children": [
212213
{
213214
"name": "file_two.py",
214-
"type_": TestNodeTypeEnum.file,
215+
"type_": NodeTypeEnum.file,
215216
"path": file_path,
216217
"children": [
217218
{
218219
"name": "DiscoveryErrorTwo",
219220
"path": file_path,
220-
"type_": TestNodeTypeEnum.class_,
221+
"type_": NodeTypeEnum.class_,
221222
"children": [
222223
{
223224
"name": "test_one",
224225
"path": file_path,
225-
"type_": TestNodeTypeEnum.test,
226+
"type_": NodeTypeEnum.test,
226227
"lineno": "14",
227228
"id_": file_path + "\\" + "DiscoveryErrorTwo" + "\\" + "test_one",
228229
},
229230
{
230231
"name": "test_two",
231232
"path": file_path,
232-
"type_": TestNodeTypeEnum.test,
233+
"type_": NodeTypeEnum.test,
233234
"lineno": "17",
234235
"id_": file_path + "\\" + "DiscoveryErrorTwo" + "\\" + "test_two",
235236
},

python_files/tests/unittestadapter/test_utils.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import pytest
1010

11+
from unittestadapter.pvsc_utils import TestNode as Node
12+
from unittestadapter.pvsc_utils import TestNodeTypeEnum as NodeTypeEnum
1113
from unittestadapter.pvsc_utils import (
12-
TestNode,
13-
TestNodeTypeEnum,
1414
build_test_tree,
1515
get_child_node,
1616
get_test_case,
@@ -65,27 +65,27 @@ def test_simple_test_cases(directory, pattern, expected) -> None:
6565

6666
def test_get_existing_child_node() -> None:
6767
"""The get_child_node fuction should return the child node of a test tree if it exists."""
68-
tree: TestNode = {
68+
tree: Node = {
6969
"name": "root",
7070
"path": "foo",
71-
"type_": TestNodeTypeEnum.folder,
71+
"type_": NodeTypeEnum.folder,
7272
"children": [
7373
{
7474
"name": "childOne",
7575
"path": "child/one",
76-
"type_": TestNodeTypeEnum.folder,
76+
"type_": NodeTypeEnum.folder,
7777
"children": [
7878
{
7979
"name": "nestedOne",
8080
"path": "nested/one",
81-
"type_": TestNodeTypeEnum.folder,
81+
"type_": NodeTypeEnum.folder,
8282
"children": [],
8383
"id_": "nested/one",
8484
},
8585
{
8686
"name": "nestedTwo",
8787
"path": "nested/two",
88-
"type_": TestNodeTypeEnum.folder,
88+
"type_": NodeTypeEnum.folder,
8989
"children": [],
9090
"id_": "nested/two",
9191
},
@@ -95,15 +95,15 @@ def test_get_existing_child_node() -> None:
9595
{
9696
"name": "childTwo",
9797
"path": "child/two",
98-
"type_": TestNodeTypeEnum.folder,
98+
"type_": NodeTypeEnum.folder,
9999
"children": [],
100100
"id_": "child/two",
101101
},
102102
],
103103
"id_": "foo",
104104
}
105105

106-
get_child_node("childTwo", "child/two", TestNodeTypeEnum.folder, tree)
106+
get_child_node("childTwo", "child/two", NodeTypeEnum.folder, tree)
107107
tree_copy = tree.copy()
108108

109109
# Check that the tree didn't get mutated by get_child_node.
@@ -112,27 +112,27 @@ def test_get_existing_child_node() -> None:
112112

113113
def test_no_existing_child_node() -> None:
114114
"""The get_child_node fuction should add a child node to a test tree and return it if it does not exist."""
115-
tree: TestNode = {
115+
tree: Node = {
116116
"name": "root",
117117
"path": "foo",
118-
"type_": TestNodeTypeEnum.folder,
118+
"type_": NodeTypeEnum.folder,
119119
"children": [
120120
{
121121
"name": "childOne",
122122
"path": "child/one",
123-
"type_": TestNodeTypeEnum.folder,
123+
"type_": NodeTypeEnum.folder,
124124
"children": [
125125
{
126126
"name": "nestedOne",
127127
"path": "nested/one",
128-
"type_": TestNodeTypeEnum.folder,
128+
"type_": NodeTypeEnum.folder,
129129
"children": [],
130130
"id_": "nested/one",
131131
},
132132
{
133133
"name": "nestedTwo",
134134
"path": "nested/two",
135-
"type_": TestNodeTypeEnum.folder,
135+
"type_": NodeTypeEnum.folder,
136136
"children": [],
137137
"id_": "nested/two",
138138
},
@@ -142,7 +142,7 @@ def test_no_existing_child_node() -> None:
142142
{
143143
"name": "childTwo",
144144
"path": "child/two",
145-
"type_": TestNodeTypeEnum.folder,
145+
"type_": NodeTypeEnum.folder,
146146
"children": [],
147147
"id_": "child/two",
148148
},
@@ -154,7 +154,7 @@ def test_no_existing_child_node() -> None:
154154
tree_before = tree.copy()
155155
tree_before["children"] = tree["children"][:]
156156

157-
get_child_node("childThree", "child/three", TestNodeTypeEnum.folder, tree)
157+
get_child_node("childThree", "child/three", NodeTypeEnum.folder, tree)
158158

159159
tree_after = tree.copy()
160160
tree_after["children"] = tree_after["children"][:-1]
@@ -174,33 +174,33 @@ def test_build_simple_tree() -> None:
174174
pattern = "utils_simple_tree*"
175175
file_path = os.fsdecode(pathlib.PurePath(TEST_DATA_PATH, "utils_simple_tree.py"))
176176

177-
expected: TestNode = {
177+
expected: Node = {
178178
"path": start_dir,
179-
"type_": TestNodeTypeEnum.folder,
179+
"type_": NodeTypeEnum.folder,
180180
"name": ".data",
181181
"children": [
182182
{
183183
"name": "utils_simple_tree.py",
184-
"type_": TestNodeTypeEnum.file,
184+
"type_": NodeTypeEnum.file,
185185
"path": file_path,
186186
"children": [
187187
{
188188
"name": "TreeOne",
189189
"path": file_path,
190-
"type_": TestNodeTypeEnum.class_,
190+
"type_": NodeTypeEnum.class_,
191191
"children": [
192192
{
193193
"name": "test_one",
194194
"path": file_path,
195-
"type_": TestNodeTypeEnum.test,
195+
"type_": NodeTypeEnum.test,
196196
"lineno": "13",
197197
"id_": file_path + "\\" + "TreeOne" + "\\" + "test_one",
198198
"runID": "utils_simple_tree.TreeOne.test_one",
199199
},
200200
{
201201
"name": "test_two",
202202
"path": file_path,
203-
"type_": TestNodeTypeEnum.test,
203+
"type_": NodeTypeEnum.test,
204204
"lineno": "16",
205205
"id_": file_path + "\\" + "TreeOne" + "\\" + "test_two",
206206
"runID": "utils_simple_tree.TreeOne.test_two",
@@ -230,33 +230,33 @@ def test_build_decorated_tree() -> None:
230230
pattern = "utils_decorated_tree*"
231231
file_path = os.fsdecode(pathlib.PurePath(TEST_DATA_PATH, "utils_decorated_tree.py"))
232232

233-
expected: TestNode = {
233+
expected: Node = {
234234
"path": start_dir,
235-
"type_": TestNodeTypeEnum.folder,
235+
"type_": NodeTypeEnum.folder,
236236
"name": ".data",
237237
"children": [
238238
{
239239
"name": "utils_decorated_tree.py",
240-
"type_": TestNodeTypeEnum.file,
240+
"type_": NodeTypeEnum.file,
241241
"path": file_path,
242242
"children": [
243243
{
244244
"name": "TreeOne",
245245
"path": file_path,
246-
"type_": TestNodeTypeEnum.class_,
246+
"type_": NodeTypeEnum.class_,
247247
"children": [
248248
{
249249
"name": "test_one",
250250
"path": file_path,
251-
"type_": TestNodeTypeEnum.test,
251+
"type_": NodeTypeEnum.test,
252252
"lineno": "24",
253253
"id_": file_path + "\\" + "TreeOne" + "\\" + "test_one",
254254
"runID": "utils_decorated_tree.TreeOne.test_one",
255255
},
256256
{
257257
"name": "test_two",
258258
"path": file_path,
259-
"type_": TestNodeTypeEnum.test,
259+
"type_": NodeTypeEnum.test,
260260
"lineno": "28",
261261
"id_": file_path + "\\" + "TreeOne" + "\\" + "test_two",
262262
"runID": "utils_decorated_tree.TreeOne.test_two",

0 commit comments

Comments
 (0)