pytest-camel-collect


Namepytest-camel-collect JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/theY4Kman/pytest-camel-collect
SummaryEnable CamelCase-aware pytest class collection
upload_time2020-08-02 00:11:24
maintainer
docs_urlNone
authorZach "theY4Kman" Kanzler
requires_python>=3.6
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-camel-collect
[![PyPI version](https://badge.fury.io/py/pytest-camel-collect.svg)](https://badge.fury.io/py/pytest-camel-collect)

Allow pytest to respect word boundaries of CamelCaseWords in class name patterns.


# Installation

```bash
pip install pytest-camel-collect
```


# Usage

This plug-in augments the pattern matching of [`python_classes`](https://docs.pytest.org/en/4.0.2/reference.html#confval-python_classes)
in your _pytest.ini_, _tox.ini_, or _setup.cfg_ file.

A `-` (dash) now represents a CamelCase word boundary.

```ini
[pytest]
python_classes = Camel-*
```

`Camel-*` will match class names like `CamelClub` and `CamelCamelCamel`, but not `Camelizer`.


# Why?

Mixin classes can be helpful to reduce boilerplate. One might use these mixin classes
to add tests verifying API response status codes when authenticated as different users:

```python
class ForbidsAnonymousUsers:
    class TestAnonymousUsersAreForbidden:
        @pytest.fixture
        def user(self):
            return AnonymousUser()

        def test_anonymous_user_is_forbidden(self, response):
            assert response.status_code == 401

class ForbidsNonAdmins:
    class TestNonAdminsAreForbidden:
        @pytest.fixture
        def user(self):
            return User(is_admin=False)

        def test_non_admin_is_forbidden(self, response):
            assert response.status_code == 401
```

Now, these mixins can be used to declare "traits" of certain test environments:

```python
class DescribeMyAPIEndpoint(BaseAPITest):
    @pytest.fixture
    def url(self):
        return '/my-endpoint'

    class DescribeList(
        ForbidsAnonymousUsers,
    ):
        @pytest.fixture
        def method(self):
            return 'GET'

    class DescribeCreate(
        ForbidsAnonymousUsers,
        ForbidsNonAdmins,
    ):
        @pytest.fixture
        def method(self):
            return 'POST'
```

As it goes, business requirements change, and the API endpoint must now respond differently
depending on the user's language.

No sweat! As experts in nameology, we add well-named context classes to test other languages:

```python

class DescribeMyAPIEndpoint(BaseAPITest):
    # ...

    class DescribeCreate(
        ForbidsAnonymousUsers,
        ForbidsNonAdmins,
    ):
        # ...

        class ForEnglishSpeakers:
            @pytest.fixture
            def user(self, user):
                user.language = 'english'
                return user

            def it_returns_english(self, response):
                assert response['message'] == 'Created new thing'

        class ForSpanishSpeakers:
            @pytest.fixture
            def user(self, user):
                user.language = 'spanish'
                return user

            def it_returns_spanish(self, response):
                assert response['message'] == 'Creado cosa nueva'
```

Hmmm, but when pytest is executed, it doesn't collect our two new tests...

Ah, right! `python_classes` in _pytest.ini_!

```ini
[pytest]
python_classes = Test* Describe* For*
```

Run pytest again and it picks up our tests! Oh, and also picks up 
our `ForbidsAnonymousUsers` and `ForbidsNonAdmins` mixins... but because
they don't inherit `BaseAPITest`, the `response` fixture doesn't exist,
and they fail.

_What ever will we do?_

**Introducing: pytest-camel-collect**, the pytest plugin enabling _you_,
the hard-working, dependable, definitely-not-sleep-deprived developer
to explicitly match CamelCase words during pytest collection.

No longer must you run tests from your `ForbidsAnonymousUsers` mixin,
just because you also want to run tests in your `ForSpanishSpeakers` context!
_Hell no!_

```ini
[pytest]
python_classes = Test-* Describe-* For-*
```

That's the spirit! Now, `TestStuff` will be collected, but not `Testimony`;
`DescribeStuff` will be collected, but not `DescribesCosas`; and most importantly,
`ForSpanishSpeakers` will be collected, but not `ForbidsAnonymousUsers`.


# Development

To play around with the project and run its tests:

 1. Clone the repo
 2. In a virtualenv (or whatever you wanna do, I don't control you), run `pip install -e .[dev,test]`
 3. Run `py.test` to run the tests



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/theY4Kman/pytest-camel-collect",
    "name": "pytest-camel-collect",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Zach \"theY4Kman\" Kanzler",
    "author_email": "they4kman@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/dc/ac/f7bf8eb7b41bf73a235c885c05bba0cd211c27318566690896adc1ed89dd/pytest-camel-collect-1.0.2.tar.gz",
    "platform": "",
    "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\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Enable CamelCase-aware pytest class collection",
    "version": "1.0.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "284058e7cbc914beb25701d2d191d2b1",
                "sha256": "d119d4908616d4999bc7b440d7aa71057d89334646ffc17f656c8977c619e945"
            },
            "downloads": -1,
            "filename": "pytest_camel_collect-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "284058e7cbc914beb25701d2d191d2b1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 6484,
            "upload_time": "2020-08-02T00:11:23",
            "upload_time_iso_8601": "2020-08-02T00:11:23.363439Z",
            "url": "https://files.pythonhosted.org/packages/ed/20/21a8093330ab5c4bb421d647bc8dc698031a38f7404d05a4c6efa789919d/pytest_camel_collect-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "49d90ca918d5d2d8bdd8ab31cb4d810d",
                "sha256": "de4d2a54db3f5dd743ab90c350f9481b19cd713684e4feae893121c728b0f09c"
            },
            "downloads": -1,
            "filename": "pytest-camel-collect-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "49d90ca918d5d2d8bdd8ab31cb4d810d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5600,
            "upload_time": "2020-08-02T00:11:24",
            "upload_time_iso_8601": "2020-08-02T00:11:24.455719Z",
            "url": "https://files.pythonhosted.org/packages/dc/ac/f7bf8eb7b41bf73a235c885c05bba0cd211c27318566690896adc1ed89dd/pytest-camel-collect-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-08-02 00:11:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "theY4Kman",
    "error": "Could not fetch GitHub repository",
    "lcname": "pytest-camel-collect"
}
        
Elapsed time: 0.14950s