Fix type errors after adding types to the py dependency#6511
Fix type errors after adding types to the py dependency#6511bluetech merged 1 commit intopytest-dev:masterfrom
py dependency#6511Conversation
| """ the file system path of the test module which collected this test. """ | ||
| return self._pyfuncitem.fspath | ||
| # TODO: Remove ignore once _pyfuncitem is properly typed. | ||
| return self._pyfuncitem.fspath # type: ignore |
There was a problem hiding this comment.
Use the error code here? (see --show-error-codes, could be added to the config probably) (with flake-ignore then)
There was a problem hiding this comment.
We should probably do them all at once, maybe on the next mypy bump.
| @cached_property | ||
| def location(self) -> Tuple[str, Optional[int], str]: | ||
| location = self.reportinfo() | ||
| assert isinstance(location[0], py.path.local), location[0] |
There was a problem hiding this comment.
You've removed the change from reportinfo, right? (from the initial Git tree)
| class MyFunction(pytest.Function): | ||
| def reportinfo(self): | ||
| return "ABCDE", 42, "custom" | ||
| return py.path.local("foo"), 42, "custom" |
There was a problem hiding this comment.
That's kind of an API change - I've noticed this myself that the tests seem to be the only things using str.
Ok with me in general, just wanted to mention this, i.e. some plugins might return strings there (but likely fail then afterwards, depending on where it is used I guess?)
Maybe this could/should have a test?
There was a problem hiding this comment.
The _bestrelpathcache backing this only works with py.path.local, that it returned something for str was accidental and incorrect. So I think the assert just codifies the current behavior.
Only this test trigerred the assert, and it's just a mock, so I think it should be fine.
This is in preparation for adding type stubs to
py. See pytest-dev/py#232.These changes make mypy clean both before and after.