|
12 | 12 | from textwrap import dedent |
13 | 13 | from typing import List |
14 | 14 | from typing import Tuple |
| 15 | +from typing import Union |
15 | 16 |
|
16 | 17 | import py |
17 | 18 |
|
@@ -280,15 +281,16 @@ def getmodpath(self, stopatmodule=True, includemodule=False): |
280 | 281 | parts.reverse() |
281 | 282 | return ".".join(parts) |
282 | 283 |
|
283 | | - def reportinfo(self) -> Tuple[str, int, str]: |
| 284 | + def reportinfo(self) -> Tuple[Union[py.path.local, str], int, str]: |
284 | 285 | # XXX caching? |
285 | 286 | obj = self.obj |
286 | 287 | compat_co_firstlineno = getattr(obj, "compat_co_firstlineno", None) |
287 | 288 | if isinstance(compat_co_firstlineno, int): |
288 | 289 | # nose compatibility |
289 | | - fspath = sys.modules[obj.__module__].__file__ |
290 | | - if fspath.endswith(".pyc"): |
291 | | - fspath = fspath[:-1] |
| 290 | + file_path = sys.modules[obj.__module__].__file__ |
| 291 | + if file_path.endswith(".pyc"): |
| 292 | + file_path = file_path[:-1] |
| 293 | + fspath = file_path # type: Union[py.path.local, str] |
292 | 294 | lineno = compat_co_firstlineno |
293 | 295 | else: |
294 | 296 | fspath, lineno = getfslineno(obj) |
@@ -367,7 +369,12 @@ def collect(self): |
367 | 369 | if not isinstance(res, list): |
368 | 370 | res = [res] |
369 | 371 | values.extend(res) |
370 | | - values.sort(key=lambda item: item.reportinfo()[:2]) |
| 372 | + |
| 373 | + def sort_key(item): |
| 374 | + fspath, lineno, _ = item.reportinfo() |
| 375 | + return (str(fspath), lineno) |
| 376 | + |
| 377 | + values.sort(key=sort_key) |
371 | 378 | return values |
372 | 379 |
|
373 | 380 | def _makeitem(self, name, obj): |
|
0 commit comments