{ "info": { "author": "Zach \"theY4Kman\" Kanzler", "author_email": "they4kman@gmail.com", "bugtrack_url": null, "classifiers": [ "Framework :: Pytest" ], "description": "# pytest-camel-collect\n[![PyPI version](https://badge.fury.io/py/pytest-camel-collect.svg)](https://badge.fury.io/py/pytest-camel-collect)\n\nAllow pytest to respect word boundaries of CamelCaseWords in class name patterns.\n\n\n# Installation\n\n```bash\npip install pytest-camel-collect\n```\n\n\n# Usage\n\nThis plug-in augments the pattern matching of [`python_classes`](https://docs.pytest.org/en/4.0.2/reference.html#confval-python_classes)\nin your _pytest.ini_, tox.ini, or setup.cfg file.\n\nA `-` (dash) now represents a CamelCase word boundary.\n\n```ini\n[pytest]\npython_classes = Camel-*\n```\n\n`Camel-*` will match class names like `CamelClub` and `CamelCamelCamel`, but not `Camelizer`.\n\n\n# Why?\n\nMixin classes can be helpful to reduce boilerplate. One might use these mixin classes\nto add tests verifying API response status codes when authenticated as different users:\n\n```python\nclass ForbidsAnonymousUsers:\n class TestAnonymousUsersAreForbidden:\n @pytest.fixture\n def user(self):\n return AnonymousUser()\n \n def test_anonymous_user_is_forbidden(self, response):\n assert response.status_code == 401\n\nclass ForbidsNonAdmins:\n class TestNonAdminsAreForbidden:\n @pytest.fixture\n def user(self):\n return User(is_admin=False)\n \n def test_non_admin_is_forbidden(self, response):\n assert response.status_code == 401\n```\n\nNow, these mixins can be used to declare \"traits\" of certain test environments:\n\n```python\nclass DescribeMyAPIEndpoint(BaseAPITest):\n @pytest.fixture\n def url(self):\n return '/my-endpoint'\n\n class DescribeList(\n ForbidsAnonymousUsers,\n ):\n @pytest.fixture\n def method(self):\n return 'GET'\n\n class DescribeCreate(\n ForbidsAnonymousUsers,\n ForbidsNonAdmins,\n ):\n @pytest.fixture\n def method(self):\n return 'POST'\n```\n\nAs it goes, business requirements change, and the API endpoint must now respond differently\ndepending on the user's language.\n\nNo sweat! As experts in nameology, we add well-named context classes to test other languages:\n\n```python\n\nclass DescribeMyAPIEndpoint(BaseAPITest):\n # ...\n\n class DescribeCreate(\n ForbidsAnonymousUsers,\n ForbidsNonAdmins,\n ):\n # ...\n\n class ForEnglishSpeakers:\n @pytest.fixture\n def user(self, user):\n user.language = 'english'\n return user\n\n def it_returns_english(self, response):\n assert response['message'] == 'Created new thing'\n\n class ForSpanishSpeakers:\n @pytest.fixture\n def user(self, user):\n user.language = 'spanish'\n return user\n\n def it_returns_spanish(self, response):\n assert response['message'] == 'Creado cosa nueva'\n```\n\nHmmm, but when pytest is executed, it doesn't collect our two new tests...\n\nAh, right! `python_classes` in _pytest.ini_!\n\n```ini\n[pytest]\npython_classes = Test* Describe* For*\n```\n\nRun pytest again and it picks up our tests! Oh, and also picks up \nour `ForbidsAnonymousUsers` and `ForbidsNonAdmins` mixins... but because\nthey don't inherit `BaseAPITest`, the `response` fixture doesn't exist,\nand they fail.\n\n_What ever will we do?_\n\n**Introducing: pytest-camel-collect**, the pytest plugin enabling _you_,\nthe hard-working, dependable, definitely-not-sleep-deprived developer\nto explicitly match CamelCase words during pytest collection.\n\nNo longer must you run tests from your `ForbidsAnonymousUsers` mixin,\njust because you also want to run tests in your `ForSpanishSpeakers` context!\n_Hell no!_\n\n```ini\n[pytest]\npython_classes = Test-* Describe-* For-*\n```\n\nThat's the spirit! Now, `TestStuff` will be collected, but not `Testimony`;\n`DescribeStuff` will be collected, but not `DescribesCosas`; and most importantly,\n`ForSpanishSpeakers` will be collected, but not `ForbidsAnonymousUsers`.\n\n\n# Development\n\nTo play around with the project and run its tests:\n\n 1. Clone the repo\n 2. In a virtualenv (or whatever you wanna do, I don't control you), run `pip install -e .[dev,test]`\n 3. Run `py.test` to run the tests", "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-camel-collect", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "pytest-camel-collect", "package_url": "https://pypi.org/project/pytest-camel-collect/", "platform": "", "project_url": "https://pypi.org/project/pytest-camel-collect/", "project_urls": { "Homepage": "https://github.com/theY4Kman/pytest-camel-collect" }, "release_url": "https://pypi.org/project/pytest-camel-collect/1.0.1/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Enable CamelCase-aware pytest class collection", "version": "1.0.1" }, "last_serial": 4703837, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "5a897fd26d61784235bbfd92e5ecda20", "sha256": "891a035e13fc8d6f44bb2df99cc6b17a620ad71087aa91ee5782d76e2bd870c7" }, "downloads": -1, "filename": "pytest-camel-collect-1.0.0.tar.gz", "has_sig": false, "md5_digest": "5a897fd26d61784235bbfd92e5ecda20", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5094, "upload_time": "2018-12-18T04:13:16", "url": "https://files.pythonhosted.org/packages/c5/3a/f52d664fffa68ecc9e56e3529af96355d60461834cf3add67c1d1e393143/pytest-camel-collect-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "3af2587a3a9765472b099fd0b2c45e51", "sha256": "b4aa5c9837b0515424b087fd13f57a0d79c24214f1f0673c928ce70bf4ab3620" }, "downloads": -1, "filename": "pytest-camel-collect-1.0.1.tar.gz", "has_sig": false, "md5_digest": "3af2587a3a9765472b099fd0b2c45e51", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5164, "upload_time": "2018-12-18T05:39:56", "url": "https://files.pythonhosted.org/packages/f6/f4/57ad492bf43904e891ca926ddad5f1daf9d8c6d233ac659d19bb08f0358d/pytest-camel-collect-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3af2587a3a9765472b099fd0b2c45e51", "sha256": "b4aa5c9837b0515424b087fd13f57a0d79c24214f1f0673c928ce70bf4ab3620" }, "downloads": -1, "filename": "pytest-camel-collect-1.0.1.tar.gz", "has_sig": false, "md5_digest": "3af2587a3a9765472b099fd0b2c45e51", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 5164, "upload_time": "2018-12-18T05:39:56", "url": "https://files.pythonhosted.org/packages/f6/f4/57ad492bf43904e891ca926ddad5f1daf9d8c6d233ac659d19bb08f0358d/pytest-camel-collect-1.0.1.tar.gz" } ] }