Skip to content

mypy does not detect pytest-assume #9326

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

Closed
trym-b opened this issue Aug 19, 2020 · 3 comments
Closed

mypy does not detect pytest-assume #9326

trym-b opened this issue Aug 19, 2020 · 3 comments

Comments

@trym-b
Copy link

trym-b commented Aug 19, 2020

I am not sure if this is the correct place to file this issue, but the issue I am having with mypy is that it does not detect the functions added by a pytest-plugin.

I created a reproducer script:

mkdir temp_dir
python -m venv temp_dir/virtual-env || exit $?
source temp_dir/virtual-env/bin/activate || exit $?
python -m pip install pytest pytest-assume mypy || exit $?

echo "import pytest
def test_dummy() -> None:
    pytest.assume(1 != 2)
    pytest.assume(3 == 3)" >> "temp_dir/test_dummy_file.py" || exit $?

echo "Mypy version:"
mypy --version || exit $?

echo "Running pytest:"
pytest "temp_dir/test_dummy_file.py" || exit $?

echo "Running mypy:"
mypy "temp_dir/test_dummy_file.py" || exit $?

When run, I get the output:

$ ./pytest-assume.sh 
Collecting pytest
  Using cached pytest-6.0.1-py3-none-any.whl (270 kB)
Collecting pytest-assume
  Using cached pytest_assume-2.3.2-py3-none-any.whl (5.6 kB)
Collecting mypy
  Using cached mypy-0.782-cp38-cp38-manylinux1_x86_64.whl (21.7 MB)
Collecting more-itertools>=4.0.0
  Using cached more_itertools-8.4.0-py3-none-any.whl (43 kB)
Collecting toml
  Using cached toml-0.10.1-py2.py3-none-any.whl (19 kB)
Collecting py>=1.8.2
  Using cached py-1.9.0-py2.py3-none-any.whl (99 kB)
Collecting pluggy<1.0,>=0.12
  Using cached pluggy-0.13.1-py2.py3-none-any.whl (18 kB)
Collecting packaging
  Using cached packaging-20.4-py2.py3-none-any.whl (37 kB)
Collecting iniconfig
  Using cached iniconfig-1.0.1-py3-none-any.whl (4.2 kB)
Collecting attrs>=17.4.0
  Using cached attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting typing-extensions>=3.7.4
  Using cached typing_extensions-3.7.4.2-py3-none-any.whl (22 kB)
Collecting typed-ast<1.5.0,>=1.4.0
  Using cached typed_ast-1.4.1-cp38-cp38-manylinux1_x86_64.whl (768 kB)
Collecting mypy-extensions<0.5.0,>=0.4.3
  Using cached mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
Collecting pyparsing>=2.0.2
  Using cached pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
Collecting six
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Installing collected packages: more-itertools, toml, py, pluggy, pyparsing, six, packaging, iniconfig, attrs, pytest, pytest-assume, typing-extensions, typed-ast, mypy-extensions, mypy
Successfully installed attrs-19.3.0 iniconfig-1.0.1 more-itertools-8.4.0 mypy-0.782 mypy-extensions-0.4.3 packaging-20.4 pluggy-0.13.1 py-1.9.0 pyparsing-2.4.7 pytest-6.0.1 pytest-assume-2.3.2 six-1.15.0 toml-0.10.1 typed-ast-1.4.1 typing-extensions-3.7.4.2
Mypy version:
mypy 0.782
Running pytest:
================================= test session starts =================================
platform linux -- Python 3.8.2, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /home/trym/testing/bug-mypy
plugins: assume-2.3.2
collected 1 item                                                                      

temp_dir/test_dummy_file.py .                                                   [100%]

================================== 1 passed in 0.02s ==================================
Running mypy:
temp_dir/test_dummy_file.py:3: error: Module has no attribute "assume"
temp_dir/test_dummy_file.py:4: error: Module has no attribute "assume"
Found 2 errors in 1 file (checked 1 source file)

I would expect mypy to be able to find this function, but this is not the case. Is this a quirk of pytest-plugins or is this a bug in mypy?

@gvanrossum
Copy link
Member

Is there a typeshed stub for pytest? Does it have a sub-stub for assume? I’m guessing the answers are Yes, No, respectively. Then it would be a typeshed issue.

@trym-b
Copy link
Author

trym-b commented Aug 19, 2020

I was under the impression that they had enabled type hint in pytest with the latest 6.0.1 release, seen in this issue: pytest-dev/pytest#3342, but this is not the case for pytest-assume.
So the solution is to either add type-hints to the plugin itself, of add a pytest_assume entry in typeshed? If yes, I then I will close this issue.

@gvanrossum
Copy link
Member

Since pytest went the way of inline typing and a py.typed marker file, I believe this needs to be added there, not to typeshed.

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

No branches or pull requests

2 participants