8
8
9
9
from _pytest .config import ExitCode
10
10
from _pytest .config import UsageError
11
+ from _pytest .main import CollectionArgument
11
12
from _pytest .main import resolve_collection_argument
12
13
from _pytest .main import validate_basetemp
13
14
from _pytest .pytester import Pytester
@@ -133,26 +134,38 @@ def invocation_path(self, pytester: Pytester) -> Path:
133
134
134
135
def test_file (self , invocation_path : Path ) -> None :
135
136
"""File and parts."""
136
- assert resolve_collection_argument (invocation_path , "src/pkg/test.py" ) == (
137
- invocation_path / "src/pkg/test.py" ,
138
- [],
137
+ assert resolve_collection_argument (
138
+ invocation_path , "src/pkg/test.py"
139
+ ) == CollectionArgument (
140
+ path = invocation_path / "src/pkg/test.py" ,
141
+ parts = [],
139
142
)
140
- assert resolve_collection_argument (invocation_path , "src/pkg/test.py::" ) == (
141
- invocation_path / "src/pkg/test.py" ,
142
- ["" ],
143
+ assert resolve_collection_argument (
144
+ invocation_path , "src/pkg/test.py::"
145
+ ) == CollectionArgument (
146
+ path = invocation_path / "src/pkg/test.py" ,
147
+ parts = ["" ],
143
148
)
144
149
assert resolve_collection_argument (
145
150
invocation_path , "src/pkg/test.py::foo::bar"
146
- ) == (invocation_path / "src/pkg/test.py" , ["foo" , "bar" ])
151
+ ) == CollectionArgument (
152
+ path = invocation_path / "src/pkg/test.py" ,
153
+ parts = ["foo" , "bar" ],
154
+ )
147
155
assert resolve_collection_argument (
148
156
invocation_path , "src/pkg/test.py::foo::bar::"
149
- ) == (invocation_path / "src/pkg/test.py" , ["foo" , "bar" , "" ])
157
+ ) == CollectionArgument (
158
+ path = invocation_path / "src/pkg/test.py" ,
159
+ parts = ["foo" , "bar" , "" ],
160
+ )
150
161
151
162
def test_dir (self , invocation_path : Path ) -> None :
152
163
"""Directory and parts."""
153
- assert resolve_collection_argument (invocation_path , "src/pkg" ) == (
154
- invocation_path / "src/pkg" ,
155
- [],
164
+ assert resolve_collection_argument (
165
+ invocation_path , "src/pkg"
166
+ ) == CollectionArgument (
167
+ path = invocation_path / "src/pkg" ,
168
+ parts = [],
156
169
)
157
170
158
171
with pytest .raises (
@@ -169,13 +182,21 @@ def test_pypath(self, invocation_path: Path) -> None:
169
182
"""Dotted name and parts."""
170
183
assert resolve_collection_argument (
171
184
invocation_path , "pkg.test" , as_pypath = True
172
- ) == (invocation_path / "src/pkg/test.py" , [])
185
+ ) == CollectionArgument (
186
+ path = invocation_path / "src/pkg/test.py" ,
187
+ parts = [],
188
+ )
173
189
assert resolve_collection_argument (
174
190
invocation_path , "pkg.test::foo::bar" , as_pypath = True
175
- ) == (invocation_path / "src/pkg/test.py" , ["foo" , "bar" ])
176
- assert resolve_collection_argument (invocation_path , "pkg" , as_pypath = True ) == (
177
- invocation_path / "src/pkg" ,
178
- [],
191
+ ) == CollectionArgument (
192
+ path = invocation_path / "src/pkg/test.py" ,
193
+ parts = ["foo" , "bar" ],
194
+ )
195
+ assert resolve_collection_argument (
196
+ invocation_path , "pkg" , as_pypath = True
197
+ ) == CollectionArgument (
198
+ path = invocation_path / "src/pkg" ,
199
+ parts = [],
179
200
)
180
201
181
202
with pytest .raises (
@@ -186,10 +207,12 @@ def test_pypath(self, invocation_path: Path) -> None:
186
207
)
187
208
188
209
def test_parametrized_name_with_colons (self , invocation_path : Path ) -> None :
189
- ret = resolve_collection_argument (
210
+ assert resolve_collection_argument (
190
211
invocation_path , "src/pkg/test.py::test[a::b]"
212
+ ) == CollectionArgument (
213
+ path = invocation_path / "src/pkg/test.py" ,
214
+ parts = ["test[a::b]" ],
191
215
)
192
- assert ret == (invocation_path / "src/pkg/test.py" , ["test[a::b]" ])
193
216
194
217
def test_does_not_exist (self , invocation_path : Path ) -> None :
195
218
"""Given a file/module that does not exist raises UsageError."""
@@ -209,17 +232,22 @@ def test_does_not_exist(self, invocation_path: Path) -> None:
209
232
def test_absolute_paths_are_resolved_correctly (self , invocation_path : Path ) -> None :
210
233
"""Absolute paths resolve back to absolute paths."""
211
234
full_path = str (invocation_path / "src" )
212
- assert resolve_collection_argument (invocation_path , full_path ) == (
213
- Path (os .path .abspath ("src" )),
214
- [],
235
+ assert resolve_collection_argument (
236
+ invocation_path , full_path
237
+ ) == CollectionArgument (
238
+ path = Path (os .path .abspath ("src" )),
239
+ parts = [],
215
240
)
216
241
217
242
# ensure full paths given in the command-line without the drive letter resolve
218
243
# to the full path correctly (#7628)
219
244
drive , full_path_without_drive = os .path .splitdrive (full_path )
220
245
assert resolve_collection_argument (
221
246
invocation_path , full_path_without_drive
222
- ) == (Path (os .path .abspath ("src" )), [])
247
+ ) == CollectionArgument (
248
+ path = Path (os .path .abspath ("src" )),
249
+ parts = [],
250
+ )
223
251
224
252
225
253
def test_module_full_path_without_drive (pytester : Pytester ) -> None :
0 commit comments