{ "info": { "author": "Zach \"theY4Kman\" Kanzler", "author_email": "they4kman@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Framework :: Pytest", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Testing" ], "description": "# pytest-lambda\n\nDefine pytest fixtures with lambda functions.\n\n\n# Quickstart\n\n```bash\npip install pytest-lambda\n```\n\n```python\n# test_the_namerator.py\n\nfrom pytest_lambda import lambda_fixture, static_fixture\n\nfirst = static_fixture('John')\nmiddle = static_fixture('Jacob')\nlast = static_fixture('Jingleheimer-Schmidt')\n\n\nfull_name = lambda_fixture(lambda first, middle, last: f'{first} {middle} {last}')\n\n\ndef test_the_namerator(full_name):\n assert full_name == 'John Jacob Jingleheimer-Schmidt'\n```\n\n\n# Cheatsheet\n\n ```python\nimport pytest\nfrom pytest_lambda import (\n disabled_fixture,\n error_fixture,\n lambda_fixture,\n not_implemented_fixture,\n static_fixture,\n)\n\n# Basic usage\nfixture_name = lambda_fixture(lambda other_fixture: 'expression', scope='session', autouse=True)\n\n# Request fixtures by name\nfixture_name = lambda_fixture('other_fixture')\nfixture_name = lambda_fixture('other_fixture', 'another_fixture', 'cant_believe_its_not_fixture')\n\n# Reference `self` inside a class\nclass TestContext:\n fixture_name = lambda_fixture(lambda self: self.__class__.__name__, bind=True)\n\n# Parametrize\nfixture_name = lambda_fixture(params=['a', 'b'])\nfixture_name = lambda_fixture(params=['a', 'b'], ids=['A!', 'B!'])\nfixture_name = lambda_fixture(params=[pytest.param('a', id='A!'),\n pytest.param('b', id='B!')])\n\n# Use literal value (not lazily evaluated)\nfixture_name = static_fixture(42)\nfixture_name = static_fixture('just six sevens', autouse=True, scope='module')\n\n# Raise an exception if fixture is requested\nfixture_name = error_fixture(lambda: ValueError('my life has no intrinsic value'))\n\n# Or maybe don't raise the exception\nfixture_name = error_fixture(lambda other_fixture: TypeError('nope') if other_fixture else None)\n\n# Create an abstract fixture (to be overridden by the user)\nfixture_name = not_implemented_fixture()\nfixture_name = not_implemented_fixture(autouse=True, scope='session')\n\n# Disable usage of a fixture (fail early to save future head scratching)\nfixture_name = disabled_fixture()\n```\n\n\n# What else is possible?\n\nOf course, you can use lambda fixtures inside test classes:\n```python\n# test_staying_classy.py\n\nfrom pytest_lambda import lambda_fixture\n\nclass TestClassiness:\n classiness = lambda_fixture(lambda: 9000 + 1)\n\n def test_how_classy_we_is(self, classiness):\n assert classiness == 9001\n```\n\n\n### Aliasing other fixtures\n\nYou can also pass the name of another fixture, instead of a lambda:\n```python\n# test_the_bourne_identity.py\n\nfrom pytest_lambda import lambda_fixture, static_fixture\n\nagent = static_fixture('Bourne')\nwho_i_am = lambda_fixture('agent')\n\ndef test_my_identity(who_i_am):\n assert who_i_am == 'Bourne'\n```\n\n\nEven multiple fixture names can be used:\n```python\n# test_the_bourne_identity.py\n\nfrom pytest_lambda import lambda_fixture, static_fixture\n\nagent_first = static_fixture('Jason')\nagent_last = static_fixture('Bourne')\nwho_i_am = lambda_fixture('agent_first', 'agent_last')\n\ndef test_my_identity(who_i_am):\n assert who_i_am == ('Jason', 'Bourne')\n```\n\n\n#### Annotating aliased fixtures\n\nYou can force the loading of fixtures without trying to remember the name of `pytest.mark.usefixtures`\n```python\n# test_garage.py\n\nfrom pytest_lambda import lambda_fixture, static_fixture\n\ncar = static_fixture({\n 'type': 'Sweet-ass Cadillac',\n 'is_started': False,\n})\nturn_the_key = lambda_fixture(lambda car: car.update(is_started=True))\n\npreconditions = lambda_fixture('turn_the_key', autouse=True)\n\ndef test_my_caddy(car):\n assert car['is_started']\n```\n\n\n### Declaring abstract things\n\n`not_implemented_fixture` is perfect for labeling abstract parameter fixtures of test mixins\n```python\n# test_mixinalot.py\n\nimport pytest\nfrom pytest_lambda import static_fixture, not_implemented_fixture\n\nclass Dials1900MixinALot:\n butt_shape = not_implemented_fixture()\n desires = not_implemented_fixture()\n\n def it_kicks_them_nasty_thoughts(self, butt_shape, desires):\n assert butt_shape == 'round' and 'triple X throw down' in desires\n\n\n@pytest.mark.xfail\nclass DescribeMissThing(Dials1900MixinALot):\n butt_shape = static_fixture('flat')\n desires = static_fixture(['playin workout tapes by Fonda'])\n\n\nclass DescribeSistaICantResista(Dials1900MixinALot):\n butt_shape = static_fixture('round')\n desires = static_fixture(['gettin in yo Benz', 'triple X throw down'])\n```\n\n\nUse `disabled_fixture` to mark a fixture as disabled. Go figure.\n```python\n# test_ada.py\n\nimport pytest\nfrom pytest_lambda import disabled_fixture\n\nwheelchair = disabled_fixture()\n\n@pytest.mark.xfail(strict=True)\ndef test_stairs(wheelchair):\n assert wheelchair + 'floats'\n```\n\n\n### Raising exceptions\n\nYou can also raise an arbitrary exception when a fixture is requested, using `error_fixture`\n```python\n# test_bikeshed.py\n\nimport pytest\nfrom pytest_lambda import error_fixture, not_implemented_fixture, static_fixture\n\nbicycle = static_fixture('a sledgehammer')\n\ndef it_does_sweet_jumps(bicycle):\n assert bicycle + 'jump' >= '3 feet'\n\n\nclass ContextOcean:\n depth = not_implemented_fixture()\n bicycle = error_fixture(lambda bicycle, depth: (\n RuntimeError(f'Now is not the time to use that! ({bicycle})') if depth > '1 league' else None))\n\n\n class ContextDeep:\n depth = static_fixture('20,000 leagues')\n\n @pytest.mark.xfail(strict=True, raises=RuntimeError)\n def it_doesnt_flip_and_shit(self, bicycle):\n assert bicycle + 'floats'\n\n\n class ContextBeach:\n depth = static_fixture('1 inch')\n\n def it_gets_you_all_wet_but_otherwise_rides_like_a_champ(self, bicycle):\n assert 'im wet'\n```\n\n\n# Development\n\nHow can I build and test the thing locally?\n\n1. Create a virtualenv, however you prefer. Or don't, if you prefer.\n2. `pip install poetry`\n3. `poetry install` to install setuptools entrypoint, so pytest automatically loads the plugin (otherwise, you'll have to run `py.test -p pytest_lambda.plugin`)\n4. Run `py.test`. The tests will be collected from the README.md (thanks to [pytest-markdown](https://github.com/Jc2k/pytest-markdown)).\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/theY4Kman/pytest-lambda", "keywords": "pytest", "license": "MIT", "maintainer": "Zach \"theY4Kman\" Kanzler", "maintainer_email": "they4kman@gmail.com", "name": "pytest-lambda", "package_url": "https://pypi.org/project/pytest-lambda/", "platform": "", "project_url": "https://pypi.org/project/pytest-lambda/", "project_urls": { "Homepage": "https://github.com/theY4Kman/pytest-lambda", "Repository": "https://github.com/theY4Kman/pytest-lambda" }, "release_url": "https://pypi.org/project/pytest-lambda/1.1.0/", "requires_dist": [ "pytest (>=3.6,<4.6)", "wrapt (>=1.11.0,<2.0.0)" ], "requires_python": ">=3.6,<4.0", "summary": "Define pytest fixtures with lambda functions.", "version": "1.1.0" }, "last_serial": 5678797, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "fb27a4387421bc2e6d0db00dcb9490dc", "sha256": "d579c3e5b796208c6d9aa18099cc31d77fb98e06a4b3f0f12d4737e116023f4a" }, "downloads": -1, "filename": "pytest_lambda-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "fb27a4387421bc2e6d0db00dcb9490dc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 15501, "upload_time": "2018-07-29T01:59:20", "url": "https://files.pythonhosted.org/packages/fa/a5/438f53c9d4a18bd931ad37c2f5f7e93b21b1cb5127fe6f34bc8da9e1d820/pytest_lambda-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "30ee7b5cc4c8c18c10f5d13abda8052f", "sha256": "f2ca56f93aa0f7ebd4ffda23d285e0c8c2ad5287f930deb2604f9c051d1a6010" }, "downloads": -1, "filename": "pytest-lambda-0.0.1.tar.gz", "has_sig": false, "md5_digest": "30ee7b5cc4c8c18c10f5d13abda8052f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 7585, "upload_time": "2018-07-29T01:59:22", "url": "https://files.pythonhosted.org/packages/0f/4f/e9a9f9c3e07e73b0fe276557be57ec4e02b034f41b7f4621a4f7cc144ee9/pytest-lambda-0.0.1.tar.gz" } ], "0.0.1a1": [ { "comment_text": "", "digests": { "md5": "bbfab50953f51ab611c31bb6d8cf40bf", "sha256": "36cb77b7c7696b4f10ed631df20e52e46989ccc2d14e4105db34c97d04815196" }, "downloads": -1, "filename": "pytest_lambda-0.0.1a1-py3-none-any.whl", "has_sig": false, "md5_digest": "bbfab50953f51ab611c31bb6d8cf40bf", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 2870, "upload_time": "2018-07-28T16:57:06", "url": "https://files.pythonhosted.org/packages/e2/0f/1f1eff16a1a09fe8deda04a17278b373d471b60ccc800bfec31890a37751/pytest_lambda-0.0.1a1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d67e8624d610dd446cd681d4840db871", "sha256": "27291437f4f4d08ec184ac0e5813efeded4c6170eaf3cc6e915081e1bb702d13" }, "downloads": -1, "filename": "pytest-lambda-0.0.1a1.tar.gz", "has_sig": false, "md5_digest": "d67e8624d610dd446cd681d4840db871", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 2499, "upload_time": "2018-07-28T16:57:08", "url": "https://files.pythonhosted.org/packages/2f/e8/e8284c7e67b6cb3f8857351cdb1851225814c2fb7882239049741adc4ddc/pytest-lambda-0.0.1a1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "318ceaf6746919bc3881abc6e765b5de", "sha256": "535e982e07e7e97c7351c409d8efd94563910dce35c81d71a516d0114665501f" }, "downloads": -1, "filename": "pytest_lambda-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "318ceaf6746919bc3881abc6e765b5de", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 16366, "upload_time": "2018-07-29T21:10:03", "url": "https://files.pythonhosted.org/packages/99/dc/97e184ec309453f875be96fe5411365878f83bdc93eabec8be15d4dd07c8/pytest_lambda-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ac8c28411bebffa10414e65e9fe7660e", "sha256": "d0ab85067a3dd1379f0c0db903dddbdadd77b07cf7a96f324551f8540850cbd4" }, "downloads": -1, "filename": "pytest-lambda-0.0.2.tar.gz", "has_sig": false, "md5_digest": "ac8c28411bebffa10414e65e9fe7660e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 8420, "upload_time": "2018-07-29T21:10:05", "url": "https://files.pythonhosted.org/packages/40/ac/abe61d404e032ef317887f38038c50645ee4f49406a9011b28ecbae69260/pytest-lambda-0.0.2.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "2366881afbd0f72327feb913f957903e", "sha256": "74fb5b1afd3769f2abd51009ee8ec27ff15a1521e6721e15767ffd4a2930608c" }, "downloads": -1, "filename": "pytest_lambda-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "2366881afbd0f72327feb913f957903e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 17821, "upload_time": "2019-04-22T17:46:44", "url": "https://files.pythonhosted.org/packages/9e/86/dc0850fb1db78beeef8a8a5901544dabe859d79feb57326855584ecfad4a/pytest_lambda-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "894a873d1ef3e1c1a6bae5fa29c41ce2", "sha256": "0c6ba69473e162dbbf88031eb8b426a5b79adbe75d88b3c89a6a4c93797717f7" }, "downloads": -1, "filename": "pytest-lambda-0.1.0.tar.gz", "has_sig": false, "md5_digest": "894a873d1ef3e1c1a6bae5fa29c41ce2", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 8840, "upload_time": "2019-04-22T17:46:45", "url": "https://files.pythonhosted.org/packages/3f/bf/b57460106b5b307975cfc78e86033d9d5b9f3e91e3adc0ff2a7ae06d8c4e/pytest-lambda-0.1.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "419e5afe59cbec56cc4d32d9461d609a", "sha256": "8dc4e90de718779c1efe3d5d9761a04dcd466716a9fbf3a5cf33d9ce961dc4ba" }, "downloads": -1, "filename": "pytest_lambda-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "419e5afe59cbec56cc4d32d9461d609a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 9134, "upload_time": "2019-05-26T21:03:33", "url": "https://files.pythonhosted.org/packages/aa/95/2eec98c5f0a8c70064cc6bc7356e652db579aed1bf3433a88a02cf8e3ddf/pytest_lambda-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "04fb90f5e146a8fc5e5dc7d43a1cf659", "sha256": "a9e417b3d8252946d18d65a7b3e747e893ac2502f9a98f9b49811030239b8885" }, "downloads": -1, "filename": "pytest-lambda-1.0.0.tar.gz", "has_sig": false, "md5_digest": "04fb90f5e146a8fc5e5dc7d43a1cf659", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 9082, "upload_time": "2019-05-26T21:03:31", "url": "https://files.pythonhosted.org/packages/ed/19/f533bdb4b62873384dea893c858ec2efd756a1192cc10fae2d8e4883cc79/pytest-lambda-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "3012534d2dd87dd28b799894caef7f42", "sha256": "137807c9323bd0df5c023e8d5c224ebc7dfd503e98b4ba85b9dcd5bb46a8b771" }, "downloads": -1, "filename": "pytest_lambda-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3012534d2dd87dd28b799894caef7f42", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 10661, "upload_time": "2019-08-14T19:06:28", "url": "https://files.pythonhosted.org/packages/bc/b2/702c60b9c7e77b8f510a029f8068bf1a734968250de1a089939695d5ba86/pytest_lambda-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bd2a48b59bd6adbfe6ab215ed389743b", "sha256": "ade250462154b5ec1c444f5c6d0b4bc78521ab7922fcbb4550683e42c1e4b100" }, "downloads": -1, "filename": "pytest-lambda-1.1.0.tar.gz", "has_sig": false, "md5_digest": "bd2a48b59bd6adbfe6ab215ed389743b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 11476, "upload_time": "2019-08-14T19:06:27", "url": "https://files.pythonhosted.org/packages/62/0f/482742bd57b488e05102471234037ae0561ab6f72abc5c05b0aca9c17f3b/pytest-lambda-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3012534d2dd87dd28b799894caef7f42", "sha256": "137807c9323bd0df5c023e8d5c224ebc7dfd503e98b4ba85b9dcd5bb46a8b771" }, "downloads": -1, "filename": "pytest_lambda-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "3012534d2dd87dd28b799894caef7f42", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 10661, "upload_time": "2019-08-14T19:06:28", "url": "https://files.pythonhosted.org/packages/bc/b2/702c60b9c7e77b8f510a029f8068bf1a734968250de1a089939695d5ba86/pytest_lambda-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bd2a48b59bd6adbfe6ab215ed389743b", "sha256": "ade250462154b5ec1c444f5c6d0b4bc78521ab7922fcbb4550683e42c1e4b100" }, "downloads": -1, "filename": "pytest-lambda-1.1.0.tar.gz", "has_sig": false, "md5_digest": "bd2a48b59bd6adbfe6ab215ed389743b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 11476, "upload_time": "2019-08-14T19:06:27", "url": "https://files.pythonhosted.org/packages/62/0f/482742bd57b488e05102471234037ae0561ab6f72abc5c05b0aca9c17f3b/pytest-lambda-1.1.0.tar.gz" } ] }