mccabe icon indicating copy to clipboard operation
mccabe copied to clipboard

Fix handling missing hypothesmith gracefully

Open mgorny opened this issue 3 years ago • 1 comments

Fix test_mccabe not to fail to import if hypothesmith is not available. While the original code seems to attempt to handle missing hypothesmith, the file fails with NameError without it. This is because hypothesis decorators are used in global scope. Guard the whole test function to be defined only when hypothesmith is available.

mgorny avatar Jan 24 '22 10:01 mgorny

Ping.

mgorny avatar Apr 26 '22 12:04 mgorny

0e24f74 fixes build of 0.7 on macOS for py37-310.

nieder avatar Jul 10 '23 01:07 nieder

instead I'd recommend including hypothesis in your build

asottile avatar Dec 03 '23 13:12 asottile

instead I'd recommend including hypothesis in your build

Hello. Would you accept another PR that removes the try-except around hypothesis import? Currently, whenever hypothesis or hypothesmith fails to import, the traceback is very misleading. E.g. instead of:

>>> import hypothesmith
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    import hypothesmith
  File "/usr/lib/python3.13/site-packages/hypothesmith/__init__.py", line 3, in <module>
    from hypothesmith.cst import from_node
  File "/usr/lib/python3.13/site-packages/hypothesmith/cst.py", line 24, in <module>
    from .syntactic import ALLOWED_CHARS
  File "/usr/lib/python3.13/site-packages/hypothesmith/syntactic.py", line 7, in <module>
    from importlib.resources import read_text
ImportError: cannot import name 'read_text' from 'importlib.resources' (/usr/lib64/python3.13/importlib/resources/__init__.py)

We see:

...
test_mccabe.py:244: in <module>
    @settings(
E   NameError: name 'settings' is not defined

hroncok avatar Feb 22 '24 11:02 hroncok