Skip to content
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

Fix handling missing hypothesmith gracefully #92

Closed
wants to merge 1 commit into from

Conversation

mgorny
Copy link

@mgorny mgorny commented Jan 24, 2022

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.

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
Copy link
Author

mgorny commented Apr 26, 2022

Ping.

src_contents=hypothesmith.from_grammar() | hypothesmith.from_node(),
max_complexity=st.integers(min_value=1),
)
@pytest.mark.skipif(not hypothesmith, reason="hypothesmith could not be imported")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer necessary, but that's just a minor nit.

@mtelka mtelka mentioned this pull request Nov 18, 2022
@nieder
Copy link

nieder commented Jul 10, 2023

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

@asottile
Copy link
Member

asottile commented Dec 3, 2023

instead I'd recommend including hypothesis in your build

@asottile asottile closed this Dec 3, 2023
@hroncok
Copy link
Contributor

hroncok commented Feb 22, 2024

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

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.

5 participants