asyncclick icon indicating copy to clipboard operation
asyncclick copied to clipboard

AttributeError: 'Context' object has no attribute '_ctx_mgr'

Open bnavigator opened this issue 6 months ago • 2 comments

The most recent change between 8.1.7.0 and 8.1.7.1 causes the unit tests to fail:

https://github.com/python-trio/asyncclick/commit/bae29c300d341f6d48669c38d090687340a66e09#r137383936

[   31s] =================================== FAILURES ===================================
[   31s] ________________________ test_context_pushing[asyncio] _________________________
[   31s] 
[   31s]     @pytest.mark.anyio
[   31s]     async def test_context_pushing():
[   31s]         rv = []
[   31s]     
[   31s]         @click.command()
[   31s]         def cli():
[   31s]             pass
[   31s]     
[   31s]         ctx = click.Context(cli)
[   31s]     
[   31s]         @ctx.call_on_close
[   31s] >       def test_callback():
[   31s] 
[   31s] tests/test_context.py:190: 
[   31s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   31s] 
[   31s] self = <asyncclick.core.Context object at 0x7f0a5bf1c700>
[   31s] f = <function test_context_pushing.<locals>.test_callback at 0x7f0a5bf115e0>
[   31s] 
[   31s]     def call_on_close(self, f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
[   31s]         """Register a function to be called when the context tears down.
[   31s]     
[   31s]         This can be used to close resources opened during the script
[   31s]         execution. Resources that support Python's context manager
[   31s]         protocol which would be used in a ``with`` statement should be
[   31s]         registered with :meth:`with_resource` instead.
[   31s]     
[   31s]         :param f: The function to execute on teardown.
[   31s]         """
[   31s] >       return self._ctx_mgr.callback(f)
[   31s] E       AttributeError: 'Context' object has no attribute '_ctx_mgr'
[   31s] 
[   31s] ../../BUILDROOT/python-asyncclick-8.1.7.1-0.x86_64/usr/lib/python3.9/site-packages/asyncclick/core.py:627: AttributeError
[   31s] __________________________ test_context_pushing[trio] __________________________
[   31s] 
[   31s]     @pytest.mark.anyio
[   31s]     async def test_context_pushing():
[   31s]         rv = []
[   31s]     
[   31s]         @click.command()
[   31s]         def cli():
[   31s]             pass
[   31s]     
[   31s]         ctx = click.Context(cli)
[   31s]     
[   31s]         @ctx.call_on_close
[   31s] >       def test_callback():
[   31s] 
[   31s] tests/test_context.py:190: 
[   31s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   31s] 
[   31s] self = <asyncclick.core.Context object at 0x7f0a602bc850>
[   31s] f = <function test_context_pushing.<locals>.test_callback at 0x7f0a602a9820>
[   31s] 
[   31s]     def call_on_close(self, f: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
[   31s]         """Register a function to be called when the context tears down.
[   31s]     
[   31s]         This can be used to close resources opened during the script
[   31s]         execution. Resources that support Python's context manager
[   31s]         protocol which would be used in a ``with`` statement should be
[   31s]         registered with :meth:`with_resource` instead.
[   31s]     
[   31s]         :param f: The function to execute on teardown.
[   31s]         """
[   31s] >       return self._ctx_mgr.callback(f)
[   31s] E       AttributeError: 'Context' object has no attribute '_ctx_mgr'
[   31s] 
[   31s] ../../BUILDROOT/python-asyncclick-8.1.7.1-0.x86_64/usr/lib/python3.9/site-packages/asyncclick/core.py:627: AttributeError
[   31s] =========================== short test summary info ============================

click.Context does not have that attribute.

bnavigator avatar Jan 18 '24 20:01 bnavigator