Skip to content

Instantly share code, notes, and snippets.

@matham
Last active July 22, 2019 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matham/aca127c75f18474523897f6d7aebb31d to your computer and use it in GitHub Desktop.
Save matham/aca127c75f18474523897f6d7aebb31d to your computer and use it in GitHub Desktop.
$ PATH=$PATH:/e/Graphviz2.38/bin pytest ceed/tests/test_play.py
============================================================================================================= test session starts ============================================================================================================= platform win32 -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: G:\Python\libs\ceed, inifile: pytest.ini
plugins: cov-2.7.1, trio-0.5.2
collected 2 items
ceed\tests\test_play.py F. [100%]
================================================================================================================== FAILURES =================================================================================================================== ________________________________________________________________________________________________________________ test_app_leak ________________________________________________________________________________________________________________
value = <trio._core._run.Nursery object at 0x00000289B03A10F0>
async def yield_(value=None):
> return await _yield_(value)
e:\python\python37\lib\site-packages\async_generator\_impl.py:106:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ e:\python\python37\lib\site-packages\async_generator\_impl.py:99: in _yield_
return (yield _wrap(value))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
nursery = <trio._core._run.Nursery object at 0x00000289B03A10F0>
@pytest.fixture()
async def my_app(nursery):
app = SomethingInteresting()
nursery.start_soon(app.run)
yield app
app = weakref.ref(app)
gc.collect()
print('app is', app())
if app() is not None:
import objgraph
objgraph.show_chain(
objgraph.find_backref_chain(app(), objgraph.is_proper_module), filename=r'E:\sample-graph.png')
> assert False
E assert False
ceed\tests\test_play.py:31: AssertionError
------------------------------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------------------------------- I did the interesting thing
app checked
app is <test_play.SomethingInteresting object at 0x00000289B03A17B8>
Graph written to E:\msys64\tmp\objgraph-f9bn0r_0.dot (11 nodes)
Image generated as E:\sample-graph.png
import pytest
import gc
import weakref
import trio
class SomethingInteresting(object):
async def run(self):
await trio.sleep(1)
print('I did the interesting thing')
async def check_app(self):
await trio.sleep(3)
print('app checked')
@pytest.fixture()
async def my_app(nursery):
app = SomethingInteresting()
nursery.start_soon(app.run)
yield app
app = weakref.ref(app)
gc.collect()
print('app is', app())
if app() is not None:
import objgraph
objgraph.show_chain(
objgraph.find_backref_chain(app(), objgraph.is_proper_module), filename=r'E:\sample-graph.png')
assert False
async def test_app_leak(my_app):
await my_app.check_app()
async def test_non_fixture(nursery):
app = SomethingInteresting()
nursery.start_soon(app.run)
await app.check_app()
app = weakref.ref(app)
gc.collect()
print('app is', app())
if app() is not None:
assert False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment