Skip to content

Remove MypyItem.mypy_path #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2019
Merged

Remove MypyItem.mypy_path #59

merged 2 commits into from
Nov 4, 2019

Conversation

dmtucker
Copy link
Collaborator

@dmtucker dmtucker commented Oct 27, 2019

Fix #58

First, I attempted to fix MypyItem.mypy_path; however, Mypy wasn't very helpful, unfortunately.
The problem is that the code it uses to calculate the path it ultimately displays is neither conveniently grouped nor exposed in the public API. I got a copy-pasta solution working (though, it is not fully covered) in 6464322, but concerns about the maintenance burden of trying to re-create what Mypy does under-the-hood (especially if that ever changes incompatibly) begged for another solution.

The primary reason for MypyItem.mypy_path is to match the path found in Mypy output to the appropriate MypyItem. It is also used in reportinfo, which is meant to reflect the path from Mypy output (e.g. foo in foo:5: error: from mypy).

The first need can be satisfied (with os.path.abspath) by normalizing the MypyItem and Mypy output paths before matching them. As for reportinfo, the point of the header, IMO, is to clearly correspond to results produced by Pytest during a run. For example:

========================= test session starts =========================
platform darwin -- Python 3.4.10, pytest-4.6.6, py-1.8.0, pluggy-0.13.0
Using --randomly-seed=1572200516
rootdir: /Users/davidmtucker/Projects/pytest-mypy
plugins: cov-2.5.1, randomly-2.1.1, mypy-0.4.1
collected 1 item                                                      

Running mypy on 1 files... done with status 1

src/pytest_mypy.py F                                            [100%]

============================== FAILURES ===============================
_________________________ src/pytest_mypy.py __________________________
5: error: No library stub file for module 'pytest'
5: note: (Stub files are from https://github.com/python/typeshed)
====================== 1 failed in 2.60 seconds =======================

Here we see an F in the output:

src/pytest_mypy.py F                                            [100%]

The header should clearly allow me to associate the subsequent report with that F. This is a very simple example, but as the test run grows larger, I believe this becomes even more important. Pytest associates that F with src/pytest_mypy.py (which seems to be calculated here: https://github.com/pytest-dev/pytest/blob/8ccc0177c8be85c0725981b3a9e867baeebfbe33/src/_pytest/terminal.py#L290). So, making that the header seems natural:

_________________________ src/pytest_mypy.py __________________________

Since MypyItem.mypy_path is technically public, this is a backwards-incompatible change, so it will target 0.5.0 instead of 0.4.2.

@dmtucker dmtucker added this to the 0.5.0 milestone Oct 27, 2019
@dmtucker dmtucker merged commit ab7505e into realpython:master Nov 4, 2019
@dmtucker dmtucker deleted the paths branch November 4, 2019 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Paths are mismatched if they include ..
1 participant