[New-bugs-announce] [issue44469] Fix tests for "async with"

Serhiy Storchaka report at bugs.python.org
Mon Jun 21 01:38:29 EDT 2021


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

In Lib/test/test_coroutines.py some tests test that the body of the "asyn with" statement with bad context manager was not executed by setting a value of a variable in the body and checking its value after executing.

        body_executed = False
        async def foo():
            async with CM():
                body_executed = True

        with self.assertRaisesRegex(AttributeError, '__aexit__'):
            run_async(foo())
        self.assertFalse(body_executed)

The problem is that it sets the value of local variable of the inner function, and does not affect the outer variable. The test would pass even if the body was executed.

----------
components: Tests
messages: 396206
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Fix tests for "async with"
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44469>
_______________________________________


More information about the New-bugs-announce mailing list