This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author SylvainDe
Recipients SylvainDe
Date 2019-02-11.13:04:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1549890280.86.0.630330095869.issue35965@roundup.psfhosted.org>
In-reply-to
Content
On some Python versions, the following pieces of code have a different behavior which is not something I'd expect:

```

    DESCRIPT_REQUIRES_TYPE_RE = r"descriptor '\w+' requires a 'set' object but received a 'int'"

    ...

    def test_assertRaisesRegex(self):
        self.assertRaisesRegex(TypeError, DESCRIPT_REQUIRES_TYPE_RE, set.add, 0)

    def test_assertRaisesRegex_contextman(self):
        with self.assertRaisesRegex(TypeError, DESCRIPT_REQUIRES_TYPE_RE):
            set.add(0)

```

On impacted Python versions, only test_assertRaisesRegex_contextman fails while test_assertRaisesRegex works fine.

Logs for the failure:


```

======================================================================
FAIL: test_assertRaisesRegex_contextman (didyoumean_sugg_tests.SetAddIntRegexpTests)
----------------------------------------------------------------------
TypeError: descriptor 'add' for 'set' objects doesn't apply to 'int' object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/travis/build/.../didyoumean/didyoumean_sugg_tests.py", line 23, in test_assertRaisesRegex_contextman
    set.add(0)
AssertionError: "descriptor '\w+' requires a 'set' object but received a 'int'" does not match "descriptor 'add' for 'set' objects doesn't apply to 'int' object"


```


Either I am missing something or it looks like a bug to me.

If needed, more details/context can be found on the StackOverflow question I opened: https://stackoverflow.com/questions/54612348/different-error-message-when-unittest-assertraisesregex-is-called-as-a-context-m .
I can provide the details directly here if it is relevant.
History
Date User Action Args
2019-02-11 13:04:44SylvainDesetrecipients: + SylvainDe
2019-02-11 13:04:40SylvainDesetmessageid: <1549890280.86.0.630330095869.issue35965@roundup.psfhosted.org>
2019-02-11 13:04:40SylvainDelinkissue35965 messages
2019-02-11 13:04:40SylvainDecreate