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

Python 3.11 test regressions due to changed exception messages #24

Closed
mgorny opened this issue Jun 3, 2022 · 11 comments
Closed

Python 3.11 test regressions due to changed exception messages #24

mgorny opened this issue Jun 3, 2022 · 11 comments

Comments

@mgorny
Copy link
Contributor

mgorny commented Jun 3, 2022

(via tox -e py311, with Python 3.11.0b3)

============================================================== FAILURES ===============================================================
__________________________________________________ PropertyTestCase.test_literalname __________________________________________________

self = <cssutils.tests.test_property.PropertyTestCase testMethod=test_literalname>, excClass = <class 'AttributeError'>
msg = "can't set attribute", callableObj = <method-wrapper '__setattr__' of Property object at 0x7f9dfead21d0>
args = ('literalname', 'color'), kwargs = {}, excMsg = "property 'literalname' of 'Property' object has no setter"

    def assertRaisesMsg(self, excClass, msg, callableObj, *args, **kwargs):
        """
        Just like unittest.TestCase.assertRaises,
        but checks that the message is right too.
    
        Usage::
    
            self.assertRaisesMsg(
                MyException, "Exception message",
                my_function, (arg1, arg2)
                )
    
        from
        http://www.nedbatchelder.com/blog/200609.html#e20060905T064418
        """
        try:
>           callableObj(*args, **kwargs)
E           AttributeError: property 'literalname' of 'Property' object has no setter

/tmp/cssutils/cssutils/tests/basetest.py:105: AttributeError

During handling of the above exception, another exception occurred:

self = <cssutils.tests.test_property.PropertyTestCase testMethod=test_literalname>

    def test_literalname(self):
        "Property.literalname"
        p = cssutils.css.property.Property(r'c\olor', 'red')
        self.assertEqual(r'c\olor', p.literalname)
>       self.assertRaisesMsg(
            AttributeError, "can't set attribute", p.__setattr__, 'literalname', 'color'
        )

/tmp/cssutils/cssutils/tests/test_property.py:162: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <cssutils.tests.test_property.PropertyTestCase testMethod=test_literalname>, excClass = <class 'AttributeError'>
msg = "can't set attribute", callableObj = <method-wrapper '__setattr__' of Property object at 0x7f9dfead21d0>
args = ('literalname', 'color'), kwargs = {}, excMsg = "property 'literalname' of 'Property' object has no setter"

    def assertRaisesMsg(self, excClass, msg, callableObj, *args, **kwargs):
        """
        Just like unittest.TestCase.assertRaises,
        but checks that the message is right too.
    
        Usage::
    
            self.assertRaisesMsg(
                MyException, "Exception message",
                my_function, (arg1, arg2)
                )
    
        from
        http://www.nedbatchelder.com/blog/200609.html#e20060905T064418
        """
        try:
            callableObj(*args, **kwargs)
        except excClass as exc:
            excMsg = str(exc)
            if not msg:
                # No message provided: any message is fine.
                return
            elif msg in excMsg:
                # Message provided, and we got the right message: passes.
                return
            else:
                # Message provided, and it didn't match: fail!
>               raise self.failureException(
                    "Right exception, wrong message: got '%s' instead of '%s'"
                    % (excMsg, msg)
                )
E               AssertionError: Right exception, wrong message: got 'property 'literalname' of 'Property' object has no setter' instead of 'can't set attribute'

/tmp/cssutils/cssutils/tests/basetest.py:116: AssertionError
__________________________________________________ SelectorTestCase.test_specificity __________________________________________________

self = <cssutils.tests.test_selector.SelectorTestCase testMethod=test_specificity>, excClass = <class 'AttributeError'>
msg = "can't set attribute", callableObj = <function SelectorTestCase.test_specificity.<locals>._set at 0x7f9dfed3fce0>, args = ()
kwargs = {}, excMsg = "property 'specificity' of 'Selector' object has no setter"

    def assertRaisesMsg(self, excClass, msg, callableObj, *args, **kwargs):
        """
        Just like unittest.TestCase.assertRaises,
        but checks that the message is right too.
    
        Usage::
    
            self.assertRaisesMsg(
                MyException, "Exception message",
                my_function, (arg1, arg2)
                )
    
        from
        http://www.nedbatchelder.com/blog/200609.html#e20060905T064418
        """
        try:
>           callableObj(*args, **kwargs)

/tmp/cssutils/cssutils/tests/basetest.py:105: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def _set():
>       selector.specificity = 1
E       AttributeError: property 'specificity' of 'Selector' object has no setter

/tmp/cssutils/cssutils/tests/test_selector.py:386: AttributeError

During handling of the above exception, another exception occurred:

self = <cssutils.tests.test_selector.SelectorTestCase testMethod=test_specificity>

    def test_specificity(self):
        "Selector.specificity"
        selector = cssutils.css.Selector()
    
        # readonly
        def _set():
            selector.specificity = 1
    
>       self.assertRaisesMsg(AttributeError, "can't set attribute", _set)

/tmp/cssutils/cssutils/tests/test_selector.py:388: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <cssutils.tests.test_selector.SelectorTestCase testMethod=test_specificity>, excClass = <class 'AttributeError'>
msg = "can't set attribute", callableObj = <function SelectorTestCase.test_specificity.<locals>._set at 0x7f9dfed3fce0>, args = ()
kwargs = {}, excMsg = "property 'specificity' of 'Selector' object has no setter"

    def assertRaisesMsg(self, excClass, msg, callableObj, *args, **kwargs):
        """
        Just like unittest.TestCase.assertRaises,
        but checks that the message is right too.
    
        Usage::
    
            self.assertRaisesMsg(
                MyException, "Exception message",
                my_function, (arg1, arg2)
                )
    
        from
        http://www.nedbatchelder.com/blog/200609.html#e20060905T064418
        """
        try:
            callableObj(*args, **kwargs)
        except excClass as exc:
            excMsg = str(exc)
            if not msg:
                # No message provided: any message is fine.
                return
            elif msg in excMsg:
                # Message provided, and we got the right message: passes.
                return
            else:
                # Message provided, and it didn't match: fail!
>               raise self.failureException(
                    "Right exception, wrong message: got '%s' instead of '%s'"
                    % (excMsg, msg)
                )
E               AssertionError: Right exception, wrong message: got 'property 'specificity' of 'Selector' object has no setter' instead of 'can't set attribute'

/tmp/cssutils/cssutils/tests/basetest.py:116: AssertionError
@jaraco
Copy link
Owner

jaraco commented Jun 3, 2022

Thanks for the report. I do intend to add Python 3.11 support. I'm delayed due to actions/setup-python#213.

@jaraco
Copy link
Owner

jaraco commented Jun 8, 2022

With 141245e, tests now run against Python 3.11 in CI.

jaraco added a commit that referenced this issue Jun 8, 2022
@jaraco
Copy link
Owner

jaraco commented Jun 8, 2022

Ugh. Once again, I'm finding the lxml dependency means the pipelines are broken in Python 3.11 until lxml provides binary builds for that Python version.

@mgorny
Copy link
Contributor Author

mgorny commented Jun 8, 2022

At least on non-Windows targets, I guess you could also just install the needed packages and let lxml be built from source.

@mgorny
Copy link
Contributor Author

mgorny commented Jun 8, 2022

For Linux, you could copy-paste it from https://github.com/pkgcore/pkgcheck/blob/master/.github/workflows/test.yml#L52

@jaraco
Copy link
Owner

jaraco commented Jun 8, 2022

Good tips. Yeah, I considered that, but I'm reluctant to tweak this project and half a dozen others only for a few months and only to get partial support (Windows would still need to be disabled). Good news is in #25, I found a mostly non-invasive solution that worked well enough to get us to the point that now the tests are running in CI and the two tests you identified are marked as xfail, so we can know when they're fixed.

@jaraco
Copy link
Owner

jaraco commented Jun 8, 2022

I notice that both errors are failing with the same mode. When I searched for the error message, I found this same issue was reported here in fedora.

@jaraco
Copy link
Owner

jaraco commented Jun 8, 2022

That bug implicates bpo-46730 / python/cpython#90886.

@jaraco
Copy link
Owner

jaraco commented Jun 8, 2022

In jaraco/jaraco.test@6ef8187, I've created a function that will provide the required expectation based on Python version. I'm unsure whether I want to employ that function or simply drop the check for the expected exception message.

@jaraco
Copy link
Owner

jaraco commented Jun 8, 2022

On further consideration, I think I do want to employ that function, to keep the status quo, but maybe remove it after.

@mgorny
Copy link
Contributor Author

mgorny commented Jun 9, 2022

On further consideration, I think I do want to employ that function, to keep the status quo, but maybe remove it after.

Yeah, I think it'd be sufficient to do substring match for the property name.

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