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

Ensure config, build, toolchain, spelling, etc. issues are not masked. #4255

Merged
merged 1 commit into from
Oct 30, 2022

Conversation

rwgk
Copy link
Collaborator

@rwgk rwgk commented Oct 19, 2022

Description

Improve safety & remove obsolete comment line.

Example:

Running tests in directory "/usr/local/google/home/rwgk/forked/pybind11/tests/test_embed":
===============================================================================
All tests passed (1554 assertions in 12 test cases)

Running tests in directory "/usr/local/google/home/rwgk/forked/pybind11/tests":

============================= test session starts ==============================
platform linux -- Python 3.10.7, pytest-7.1.2, pluggy-1.0.0
C++ Info: Debian Clang 14.0.6 C++17 __pybind11_internals_v4_clang_libstdcpp_cxxabi1002_sh_def__
rootdir: /usr/local/google/home/rwgk/forked/pybind11/tests, configfile: pytest.ini
collected 769 items / 1 error

==================================== ERRORS ====================================
____________________ ERROR collecting test_eigen_tensor.py _____________________
test_eigen_tensor.py:9: in <module>
    from pybind11_tests import egen_tensor_avoid_stl_array as avoid
E   ImportError: cannot import name 'egen_tensor_avoid_stl_array' from 'pybind11_tests' (/usr/local/google/home/rwgk/forked/build_clang/lib/pybind11_tests.so)
        __builtins__ = <builtins>
        __cached__ = '/usr/local/google/home/rwgk/forked/pybind11/tests/__pycache__/test_eigen_tensor.cpython-310.pyc'
        __doc__    = None
        __file__   = '/usr/local/google/home/rwgk/forked/pybind11/tests/test_eigen_tensor.py'
        __loader__ = <_pytest.assertion.rewrite.AssertionRewritingHook object at 0x7fb9e51516f0>
        __name__   = 'test_eigen_tensor'
        __package__ = ''
        __spec__   = ModuleSpec(name='test_eigen_tensor', loader=<_pytest.assertion.rewrite.AssertionRewritingHook object at 0x7fb9e51516f0>, origin='/usr/local/google/home/rwgk/forked/pybind11/tests/test_eigen_tensor.py')
        eigen_tensor = <module 'pybind11_tests.eigen_tensor'>
        np         = <module 'numpy' from '/usr/lib/python3/dist-packages/numpy/__init__.py'>
        pytest     = <module 'pytest' from '/usr/local/lib/python3.10/dist-packages/pytest/__init__.py'>
        submodules = [<module 'pybind11_tests.eigen_tensor.c_style'>, <module 'pybind11_tests.eigen_tensor.f_style'>]
        sys        = <module 'sys' (built-in)>

The above exception was the direct cause of the following exception:
test_eigen_tensor.py:14: in <module>
    raise RuntimeError(
E   RuntimeError: import pybind11_tests.eigen_tensor_avoid_stl_array FAILED, while import pybind11_tests.eigen_tensor succeeded. Please ensure that test_eigen_tensor.cpp & test_eigen_tensor_avoid_stl_array.cpp are built together (or both are not built if Eigen is not available).
        __builtins__ = <builtins>
        __cached__ = '/usr/local/google/home/rwgk/forked/pybind11/tests/__pycache__/test_eigen_tensor.cpython-310.pyc'
        __doc__    = None
        __file__   = '/usr/local/google/home/rwgk/forked/pybind11/tests/test_eigen_tensor.py'
        __loader__ = <_pytest.assertion.rewrite.AssertionRewritingHook object at 0x7fb9e51516f0>
        __name__   = 'test_eigen_tensor'
        __package__ = ''
        __spec__   = ModuleSpec(name='test_eigen_tensor', loader=<_pytest.assertion.rewrite.AssertionRewritingHook object at 0x7fb9e51516f0>, origin='/usr/local/google/home/rwgk/forked/pybind11/tests/test_eigen_tensor.py')
        eigen_tensor = <module 'pybind11_tests.eigen_tensor'>
        np         = <module 'numpy' from '/usr/lib/python3/dist-packages/numpy/__init__.py'>
        pytest     = <module 'pytest' from '/usr/local/lib/python3.10/dist-packages/pytest/__init__.py'>
        submodules = [<module 'pybind11_tests.eigen_tensor.c_style'>, <module 'pybind11_tests.eigen_tensor.f_style'>]
        sys        = <module 'sys' (built-in)>
=========================== short test summary info ============================
ERROR test_eigen_tensor.py - RuntimeError: import pybind11_tests.eigen_tensor...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.35s ===============================

Suggested changelog entry:

@rwgk rwgk requested a review from Skylion007 October 19, 2022 14:24
@rwgk
Copy link
Collaborator Author

rwgk commented Oct 19, 2022

@lalaland I'm using this in the internal deployment.

@rwgk
Copy link
Collaborator Author

rwgk commented Oct 19, 2022

GitHub Actions are not triggering. Close-Open to see if that helps.

@rwgk rwgk closed this Oct 19, 2022
@rwgk rwgk reopened this Oct 19, 2022
@EthanSteinberg
Copy link
Collaborator

Looks good to me!

pass
except ImportError as e:
# Ensure config, build, toolchain, etc. issues are not masked here:
raise RuntimeError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like this should still be an ImportError, not a RuntimeError.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did you see the from e? That will still show the ImportError. See also the example output in the PR description. I think it's clearer to not show ImportError twice with different messages.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@rwgk But it will raise a RuntimeError, when you are propogating an ImportError with a more specific error message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried it, see below (two ImportError but with different messages). Is that what you had in mind?

Running tests in directory "/usr/local/google/home/rwgk/forked/pybind11/tests":
============================= test session starts ==============================
platform linux -- Python 3.10.7, pytest-7.1.2, pluggy-1.0.0
C++ Info: Debian Clang 14.0.6 C++17 __pybind11_internals_v4_clang_libstdcpp_cxxabi1002__
rootdir: /usr/local/google/home/rwgk/forked/pybind11/tests, configfile: pytest.ini
collected 588 items / 1 error

==================================== ERRORS ====================================
____________________ ERROR collecting test_eigen_tensor.py _____________________
ImportError while importing test module '/usr/local/google/home/rwgk/forked/pybind11/tests/test_eigen_tensor.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test_eigen_tensor.py:9: in <module>
    from pybind11_tests import egen_tensor_avoid_stl_array as avoid
E   ImportError: cannot import name 'egen_tensor_avoid_stl_array' from 'pybind11_tests' (/usr/local/google/home/rwgk/forked/build_clang/lib/pybind11_tests.so)

The above exception was the direct cause of the following exception:
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_eigen_tensor.py:14: in <module>
    raise ImportError(
E   ImportError: import pybind11_tests.eigen_tensor_avoid_stl_array FAILED, while import pybind11_tests.eigen_tensor succeeded. Please ensure that test_eigen_tensor.cpp & test_eigen_tensor_avoid_stl_array.cpp are built together (or both are not built if Eigen is not available).
=========================== short test summary info ============================
ERROR test_eigen_tensor.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.92s ===============================

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that'll be confusing.

I want something noisy: but pytest seems to suppress some information specifically for ImportError.

I think it's a kind-of-a-trap to show ImportError with two different messages. I'm very often going very fast, looking at tons of logs. I'd probably miss that the messages are different, and may miss the second.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Skylion007 Could you please let me know if you still have a preference for the double-ImportError, and why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Based on @lalaland's LGTM I'll merge this now, to get this into the smart_holder update.

@rwgk rwgk merged commit 5bc0943 into pybind:master Oct 30, 2022
@rwgk rwgk deleted the eigen_tensor_avoid_masking_issues branch October 30, 2022 20:24
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Oct 30, 2022
@rwgk rwgk removed the needs changelog Possibly needs a changelog entry label Oct 30, 2022
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.

3 participants