Pylons / pyramid

Pyramid - A Python web framework
https://trypyramid.com/
Other
3.92k stars 878 forks source link

`test_util` fails with Python 3.13 #3761

Open mattiaverga opened 4 weeks ago

mattiaverga commented 4 weeks ago

Two tests in test_util started to fail in Fedora Linux after the move to Python 3.13.0b2:

============================= test session starts ==============================
platform linux -- Python 3.13.0b2, pytest-7.4.3, pluggy-1.3.0
rootdir: /builddir/build/BUILD/python-pyramid-2.0.2-build/pyramid-2.0.2
configfile: setup.cfg
plugins: cov-4.0.0
collected 2635 items
tests/test_asset.py ...........                                          [  0%]
tests/test_authentication.py ........................................... [  2%]
........................................................................ [  4%]
................................................                         [  6%]
tests/test_authorization.py ........................                     [  7%]
tests/test_csrf.py ........................................              [  9%]
tests/test_decorator.py ....                                             [  9%]
tests/test_encode.py ...............                                     [  9%]
tests/test_events.py .......................................             [ 11%]
tests/test_exceptions.py ...........                                     [ 11%]
tests/test_httpexceptions.py ........................................... [ 13%]
................                                                         [ 13%]
tests/test_i18n.py ............................................          [ 15%]
tests/test_integration.py .............................................. [ 17%]
........................................................................ [ 20%]
......                                                                   [ 20%]
tests/test_location.py ..                                                [ 20%]
tests/test_paster.py ........                                            [ 20%]
tests/test_path.py ..................................................... [ 22%]
............................                                             [ 23%]
tests/test_predicates.py ............................................... [ 25%]
........................                                                 [ 26%]
tests/test_registry.py ....................................              [ 27%]
tests/test_renderers.py ................................................ [ 29%]
..............                                                           [ 30%]
tests/test_request.py .................................................. [ 32%]
.....                                                                    [ 32%]
tests/test_response.py ...............                                   [ 32%]
tests/test_router.py ................................................... [ 34%]
.........                                                                [ 35%]
tests/test_scripting.py .............                                    [ 35%]
tests/test_security.py ...............................................   [ 37%]
tests/test_session.py .................................................. [ 39%]
..........................................                               [ 40%]
tests/test_settings.py ...................                               [ 41%]
tests/test_static.py ................................................... [ 43%]
...                                                                      [ 43%]
tests/test_testing.py .................................................. [ 45%]
.............................                                            [ 46%]
tests/test_threadlocal.py ........                                       [ 46%]
tests/test_traversal.py ................................................ [ 48%]
.................................................                        [ 50%]
tests/test_tweens.py .....                                               [ 50%]
tests/test_url.py ...................................................... [ 52%]
.........................................................                [ 54%]
tests/test_urldispatch.py .............................................. [ 56%]
....                                                                     [ 56%]
tests/test_util.py ..............F...........F.......................... [ 58%]
........................................................................ [ 61%]
                                                                         [ 61%]
tests/test_view.py ..................................................... [ 63%]
..........................                                               [ 64%]
tests/test_viewderivers.py ............................................. [ 66%]
....................................................                     [ 68%]
tests/test_wsgi.py ...........                                           [ 68%]
tests/test_config/test_actions.py ...................................... [ 70%]
........                                                                 [ 70%]
tests/test_config/test_adapters.py .....................                 [ 71%]
tests/test_config/test_assets.py ....................................... [ 72%]
....................................................................     [ 75%]
tests/test_config/test_factories.py ..................                   [ 76%]
tests/test_config/test_i18n.py ..............                            [ 76%]
tests/test_config/test_init.py ......................................... [ 78%]
............................................................             [ 80%]
tests/test_config/test_predicates.py ................................... [ 81%]
....                                                                     [ 81%]
tests/test_config/test_rendering.py ...                                  [ 81%]
tests/test_config/test_routes.py ...............................         [ 83%]
tests/test_config/test_security.py ..............                        [ 83%]
tests/test_config/test_settings.py ........................              [ 84%]
tests/test_config/test_testing.py ............                           [ 85%]
tests/test_config/test_tweens.py .................................       [ 86%]
tests/test_config/test_views.py ........................................ [ 87%]
........................................................................ [ 90%]
........................................................................ [ 93%]
......................................................................   [ 95%]
tests/test_scripts/test_common.py ..                                     [ 96%]
tests/test_scripts/test_pdistreport.py ..                                [ 96%]
tests/test_scripts/test_prequest.py ...................                  [ 96%]
tests/test_scripts/test_proutes.py ..............................        [ 97%]
tests/test_scripts/test_pserve.py .........                              [ 98%]
tests/test_scripts/test_pshell.py .................                      [ 98%]
tests/test_scripts/test_ptweens.py .....                                 [ 99%]
tests/test_scripts/test_pviews.py .......................                [100%]
=================================== FAILURES ===================================
____________ Test_InstancePropertyHelper.test_property_without_name ____________
self = <tests.test_util.Test_InstancePropertyHelper testMethod=test_property_without_name>
    def test_property_without_name(self):
        def worker(obj):  # pragma: no cover
            pass

        foo = Dummy()
        helper = self._getTargetClass()
>       self.assertRaises(
            ValueError, helper.set_property, foo, property(worker)
        )
E       AssertionError: ValueError not raised by set_property
tests/test_util.py:74: AssertionError
____________ Test_InstancePropertyMixin.test_property_without_name _____________
self = <tests.test_util.Test_InstancePropertyMixin testMethod=test_property_without_name>
    def test_property_without_name(self):
        def worker(obj):  # pragma: no cover
            pass

        foo = self._makeOne()
>       self.assertRaises(ValueError, foo.set_property, property(worker))
E       AssertionError: ValueError not raised by set_property
tests/test_util.py:278: AssertionError

Full logs are available at https://koji.fedoraproject.org/koji/taskinfo?taskID=119046120

mattiaverga commented 3 weeks ago

with Python 3.12:

>>> def worker(obj):
...     pass
...
>>> hasattr(property(worker), '__name__')
False

With Python 3.13:

>>> def worker(obj):
...     pass
...
>>> hasattr(property(worker), '__name__')
True
>>> property(worker).__name__
'worker'
mattiaverga commented 3 weeks ago

See https://github.com/python/cpython/issues/101860

Would changing https://github.com/Pylons/pyramid/blob/ef0f6861e5b439afe43983f6c7437c30a413a34d/src/pyramid/util.py#L110-L116

to if not hasattr(callable, '__name__') or isinstance(callable, property): a suitable fix?

hroncok commented 3 weeks ago

As I understand it, that would force the caller to manually pass a name for the property, while with Python 3.13+ it is no longer necessary. I would rather adjust the test and allow this.

hroncok commented 3 weeks ago

I am working on a pull request.

hroncok commented 3 weeks ago

https://github.com/Pylons/pyramid/pull/3762