Skip to content

pytest-assume not found by mypy #7664

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 20, 2020 · 2 comments
Closed

pytest-assume not found by mypy #7664

trym-b opened this issue Aug 20, 2020 · 2 comments

Comments

@trym-b
Copy link

trym-b commented Aug 20, 2020

It seems that pytest is missing type hint support for the plugin pytest-assume, which makes mypy fail to find the function pytest.assume, even though the plugin has been installed. I was told that this issue should likely be fixed in this repo, and not by adding a type hints to typeshed (see the original issue I created over at mypy: python/mypy#9326).

Here is a reproducer, run on ubuntu-20.04:

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 $?

# Find ubuntu version
if [ -f /etc/lsb-release ]; then
    source /etc/lsb-release || exit $?
else
    echo "Error: /etc/lsb-release was not found."
    exit 1
fi

UBUNTU_VERSION="$DISTRIB_RELEASE"
echo "Running ubuntu-version: $UBUNTU_VERSION"
echo

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

echo "Pytest version:"
pytest --version || exit $?
echo

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

echo "Running pip list"
pip list || exit $?
echo

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

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

Which gives me this output when run:

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 py>=1.8.2
  Using cached py-1.9.0-py2.py3-none-any.whl (99 kB)
Collecting packaging
  Using cached packaging-20.4-py2.py3-none-any.whl (37 kB)
Collecting attrs>=17.4.0
  Using cached attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting toml
  Using cached toml-0.10.1-py2.py3-none-any.whl (19 kB)
Collecting iniconfig
  Using cached iniconfig-1.0.1-py3-none-any.whl (4.2 kB)
Collecting pluggy<1.0,>=0.12
  Using cached pluggy-0.13.1-py2.py3-none-any.whl (18 kB)
Collecting more-itertools>=4.0.0
  Using cached more_itertools-8.4.0-py3-none-any.whl (43 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 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 six
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting pyparsing>=2.0.2
  Using cached pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
Installing collected packages: py, six, pyparsing, packaging, attrs, toml, iniconfig, pluggy, more-itertools, pytest, pytest-assume, mypy-extensions, typing-extensions, typed-ast, 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
Running ubuntu-version: 20.04

Pytest version:
pytest 6.0.1

Mypy version:
mypy 0.782

Running pip list
Package           Version
----------------- -------
attrs             19.3.0 
iniconfig         1.0.1  
more-itertools    8.4.0  
mypy              0.782  
mypy-extensions   0.4.3  
packaging         20.4   
pip               20.0.2 
pkg-resources     0.0.0  
pluggy            0.13.1 
py                1.9.0  
pyparsing         2.4.7  
pytest            6.0.1  
pytest-assume     2.3.2  
setuptools        44.0.0 
six               1.15.0 
toml              0.10.1 
typed-ast         1.4.1  
typing-extensions 3.7.4.2

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/test/pytest-assume
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)
@RonnyPfannschmidt
Copy link
Member

Pytest-assume has been superseded by pytest-check @okken has archived assume a while back

Pytest-check does not monkeypatch the pytest namespace

@trym-b
Copy link
Author

trym-b commented Aug 20, 2020

Thanks for the feedback, will stop using pytest-assume. Did not know of pytest-check

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