{ "info": { "author": "Stefan C. Mueller", "author_email": "stefan.mueller@fhnw.ch", "bugtrack_url": null, "classifiers": [], "description": "utwist - Running twisted's reactor inside regular unit-tests without trial\n===========================================================================\n\nUnit testing with twisted is a bit difficult if the tests require the reactor\nto run. The official way is to use twisted's own unit testing framework called\n`trial`. It is very similar to the `unittest` module. If you would like\nto use another framework, or if you like nice IDE integration then `utwist`\nmight be the right thing for you.\n\nNote that it is considered good practice to write unit tests that\ndon't perform IO. But for integration tests, and probably some unit-tests as well,\nyou'll need a reactor running.\n\nDisclaimer: `utwist` is quite a hack. It works, I test it regularly on Linux,\nOSX, and Windows, but future versions of twisted might break it. You've been\nwarned. Hopefully twisted will come in with a better testing solution eventually.\n\nThis library is open source and released under the MIT License.\n\nYou can install it with `pip install utwist`. It doesn't need to\ncompile anything, so there shouldn't be any surprises. Even on Windows.\n\n----------------------\nLet's get going!\n----------------------\n\n.. code-block:: python\n\n from utwist import with_reactor\n \n @with_reactor\n def test_connect_with_tcp():\n point = TCP4ClientEndpoint(reactor, \"google.com\", 80)\n d = point.connect(MyFactory())\n return d\n \nIf run with `nose` this will do exactly what you'd expect. \nIt opens the network connection. The test will fail because \nthe connection wasn't closed. `utwist` checks that the reactor\nis clean at the end of the test.\n\nOf course you don't have to use `nose`. It works just as well\nwith `unittest`, and probably also with most other frameworks.\n\n----------------------\nDeferred return values\n----------------------\n \nIf the test function returns a deferred then the test will\nbe successful if the deferred resolves to a value or unsuccessful\nif the deferred errbacks.\n\n----------------------\nSetup and tear-down\n----------------------\n\nIf there is a function called `twisted_setup()` in the same class\nas the test function is defined, then this function will be invoked\nbefore the test, but already in the context of the reactor. Note that\nthe regular setup function provided by the testing framework will\nbe executed too, but not in the reactor context.\n\nAccordingly, if there is a `twisted_teardown()` it executes after the\ntest function, even if the test failed. \n\n----------------------\nSetting a timeout\n----------------------\n \nIf the test, including `twisted_setup` and `twisted_teardown`, has\nnot completed within the timeout, the test fails. The timeout defaults\nto two minutes. A timeout duration of zero disables the timeout.\n\nTo specify a different timeout pass it (in seconds) to the decorator:\n\n.. code-block:: python\n\n @with_reactor(timeout=10)\n def test_quick():\n ...\n \n----------------------\nHow does it work\n----------------------\n \nI spare you the details, but `utwist` starts the reactor in a separate thread when\nthe first test is started and lets it run until the end (the reactor cannot be restarted).\nIt uses `blockingCallFromThread()` to run the test method inside the reactor.\nOther than that there are some tricks to check if the reactor is clean, and to clean\nit if not. There is also a very dirty hack to make signals work even though the\nreactor doesn't run in the main thread.\n\n-----------------------------------\nBug Reports and other contributions\n-----------------------------------\n\nThis project is hosted here `utwist github page `_.\n \n------------\nAlternatives\n------------\n\nIf you don't mind using a cut-down version of `unittest` for your tests, nor to run\nthe tests with the special runner, then I highly recommend `trial`. It is the\nofficial unit testing tool provided by twisted.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/smurn/utwist", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "utwist", "package_url": "https://pypi.org/project/utwist/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/utwist/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/smurn/utwist" }, "release_url": "https://pypi.org/project/utwist/0.1.3/", "requires_dist": null, "requires_python": null, "summary": "Running twisted's reactor inside regular unit-tests without trial", "version": "0.1.3" }, "last_serial": 1578148, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "81f6277c199615528684d54a13b2694f", "sha256": "795dd87d614343cb617e3f07464344328cc4ad0903c28b43eded7b4070d6b7a7" }, "downloads": -1, "filename": "utwist-0.1.0.tar.gz", "has_sig": false, "md5_digest": "81f6277c199615528684d54a13b2694f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8375, "upload_time": "2014-08-28T01:45:55", "url": "https://files.pythonhosted.org/packages/3d/1c/a66cd9ee066a54cfb9a9e91c5f78c9dc89ac9674e423917f61126da92a0a/utwist-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "002eee38f9e7d1d4c76068bb14019bfa", "sha256": "567485258a9a44fda49d2b4d627a2cd120a0453294b321c8e59828846e3e1377" }, "downloads": -1, "filename": "utwist-0.1.1.zip", "has_sig": false, "md5_digest": "002eee38f9e7d1d4c76068bb14019bfa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15950, "upload_time": "2015-01-31T18:28:05", "url": "https://files.pythonhosted.org/packages/e2/90/7755a411ce689816c2f986e37c34a1d0184961cf0bf66d7ed66f59435b6b/utwist-0.1.1.zip" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "c21d7231e319b5c9030203cf9758a6e8", "sha256": "a5910fa6c9d5bbd96680e37cbbe466398e3f7ccb65bc8d777fb3b34af8490a27" }, "downloads": -1, "filename": "utwist-0.1.2.zip", "has_sig": false, "md5_digest": "c21d7231e319b5c9030203cf9758a6e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15790, "upload_time": "2015-04-02T11:47:06", "url": "https://files.pythonhosted.org/packages/50/bd/1ba363aa6b59aef98b2a9218c8169edf5ba9dfc1e6b03517a6916f3f0026/utwist-0.1.2.zip" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "5051040a48b47db3af1d91142ca00cda", "sha256": "b9d0aaca46f586421cf2fc1f924bd6d82a7607be6df3f0facdd4c67da6e784f5" }, "downloads": -1, "filename": "utwist-0.1.3.zip", "has_sig": false, "md5_digest": "5051040a48b47db3af1d91142ca00cda", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15807, "upload_time": "2015-06-04T12:47:24", "url": "https://files.pythonhosted.org/packages/89/79/5659163b2fd87cd28bde599bdf508792718017e29df9b77b76cda185afa3/utwist-0.1.3.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5051040a48b47db3af1d91142ca00cda", "sha256": "b9d0aaca46f586421cf2fc1f924bd6d82a7607be6df3f0facdd4c67da6e784f5" }, "downloads": -1, "filename": "utwist-0.1.3.zip", "has_sig": false, "md5_digest": "5051040a48b47db3af1d91142ca00cda", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15807, "upload_time": "2015-06-04T12:47:24", "url": "https://files.pythonhosted.org/packages/89/79/5659163b2fd87cd28bde599bdf508792718017e29df9b77b76cda185afa3/utwist-0.1.3.zip" } ] }