{ "info": { "author": "Stephen Moore", "author_email": "delfick755@gmail.com", "bugtrack_url": null, "classifiers": [ "Framework :: Pytest", "Topic :: Software Development :: Testing" ], "description": "Alternative Pytest Asyncio\n==========================\n\nThis plugin allows you to have async pytest fixtures and tests.\n\nThis plugin only supports python 3.6 and above.\n\nThe code here is influenced by pytest-asyncio but with some differences:\n\n* Error tracebacks from are from your tests, rather than asyncio internals\n* There is only one loop for all of the tests\n* You can manage the lifecycle of the loop yourself outside of pytest by using\n this plugin with your own loop\n* No need to explicitly mark your tests as async. (pytest-asyncio requires you\n mark your async tests because it also supports other event loops like curio\n and trio)\n\nLike pytest-asyncio it supports async tests, coroutine fixtures and async\ngenerator fixtures.\n\nChangelog\n---------\n\n0.5 - 16 August 2019\n * I made this functionality in a work project where I needed to run\n pytest.main from an existing event loop. I decided to make this it's\n own module so I can have tests for this code.\n\nRunning from your own event loop\n--------------------------------\n\nIf you want to run pytest.main from with an existing event loop then you can\ndo something like:\n\n.. code-block:: python\n\n from alt_pytest_asyncio.plugin import AltPytestAsyncioPlugin, run_coro_as_main\n import nest_asyncio\n import asyncio\n import pytest\n\n async def my_tests():\n await do_some_setup_before_pytest()\n\n plugins = [AltPytestAsyncioPlugin(loop)]\n\n try:\n code = pytest.main([], plugins=plugins)\n finally:\n # Note that alt_pytest_asyncio will make sure all your async tests\n # have been finalized by this point, even if you KeyboardInterrupt\n # the pytest.main\n await do_any_teardown_after_pytest()\n\n if code != 0:\n raise Exception(repr(code))\n\n if __name__ == '__main__':\n # Nest asyncio is required so that we can do run_until_complete in an\n # existing event loop - https://github.com/erdewit/nest_asyncio\n loop = asyncio.get_event_loop()\n nest_asyncio.apply(loop)\n\n run_coro_as_main(loop, my_tests())\n\nNote that if you don't need to run pytest from an existing event loop, you don't\nneed to do anything other than have alt_pytest_asyncio installed in your\nenvironment and you'll be able to just use async keywords on your fixtures and\ntests.\n\nTimeouts\n--------\n\nalt_pytest_asyncio registers a ``pytest.mark.async_timeout(seconds)`` mark which\nyou can use to set a timeout for your test.\n\nFor example:\n\n.. code-block:: python\n\n import pytest\n\n @pytest.mark.async_timeout(10)\n async def test_something():\n await something_that_may_take_a_while()\n\nThis test will be cancelled after 10 seconds and raise an assertion error saying\nthe test took too long and the file and line number where the test is.\n\nYou can also use the async_timeout mark on coroutine fixtures:\n\n.. code-block:: python\n\n import pytest\n\n @pytest.fixture()\n @pytest.mark.async_timeout(0.5)\n async def my_amazing_fixture():\n await asyncio.sleep(1)\n return 1\n\nAnd you can have a timeout on generator fixtures:\n\n.. code-block:: python\n\n import pytest\n\n @pytest.fixture()\n @pytest.mark.async_timeout(0.5)\n async def my_amazing_fixture():\n try:\n await asyncio.sleep(1)\n yield 1\n finally:\n await asyncio.sleep(1)\n\nNote that for generator fixtures, the timeout is applied in whole to both the\nsetup and finalization of the fixture. As in the real timeout for the entire\nfixture is essentially double the single timeout specified.\n\nThe default timeout value is 5 seconds any the closest async_timeout mark will\nbe used. i.e. on the class your test is defined on, or the module, or the session.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/delfick/alt-pytest-asyncio", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "alt-pytest-asyncio", "package_url": "https://pypi.org/project/alt-pytest-asyncio/", "platform": "", "project_url": "https://pypi.org/project/alt-pytest-asyncio/", "project_urls": { "Homepage": "https://github.com/delfick/alt-pytest-asyncio" }, "release_url": "https://pypi.org/project/alt-pytest-asyncio/0.5/", "requires_dist": null, "requires_python": ">= 3.5", "summary": "Alternative pytest plugin to pytest-asyncio", "version": "0.5" }, "last_serial": 5685521, "releases": { "0.5": [ { "comment_text": "", "digests": { "md5": "0df6cde61926a43411de09f9354a21c2", "sha256": "d0aae89ffeb7470e8e92fc6d25d54da591cd4a806683cd08722157e635323586" }, "downloads": -1, "filename": "alt_pytest_asyncio-0.5.tar.gz", "has_sig": false, "md5_digest": "0df6cde61926a43411de09f9354a21c2", "packagetype": "sdist", "python_version": "source", "requires_python": ">= 3.5", "size": 6022, "upload_time": "2019-08-16T03:47:36", "url": "https://files.pythonhosted.org/packages/05/d1/dc418f604938d29f0c0a9fe142f6cb10d31066e94eb1103144ffd83e3534/alt_pytest_asyncio-0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0df6cde61926a43411de09f9354a21c2", "sha256": "d0aae89ffeb7470e8e92fc6d25d54da591cd4a806683cd08722157e635323586" }, "downloads": -1, "filename": "alt_pytest_asyncio-0.5.tar.gz", "has_sig": false, "md5_digest": "0df6cde61926a43411de09f9354a21c2", "packagetype": "sdist", "python_version": "source", "requires_python": ">= 3.5", "size": 6022, "upload_time": "2019-08-16T03:47:36", "url": "https://files.pythonhosted.org/packages/05/d1/dc418f604938d29f0c0a9fe142f6cb10d31066e94eb1103144ffd83e3534/alt_pytest_asyncio-0.5.tar.gz" } ] }