pytest-lockable


Namepytest-lockable JSON
Version 0.10.0 PyPI version JSON
download
home_pagehttps://github.com/jupe/pytest-lockable
Summarylockable resource plugin for pytest
upload_time2024-01-24 12:25:38
maintainer
docs_urlNone
authorJussi Vatjus-Anttila
requires_python>=3.8, <4
license
keywords py.test pytest lockable resource
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-lockable

[![CircleCI](https://circleci.com/gh/jupe/pytest-lockable/tree/master.svg?style=svg)](https://circleci.com/gh/jupe/pytest-lockable/tree/master)
[![PyPI version](https://badge.fury.io/py/pytest-lockable.svg)](https://pypi.org/project/pytest-lockable/)
[![Coverage Status](https://coveralls.io/repos/github/jupe/pytest-lockable/badge.svg)](https://coveralls.io/github/jupe/pytest-lockable)

pytest plugin for lockable resources.

Replacement for Jenkins lockable -plugin.
Locking is implemented using `<resource-id>.pid` files and is released automatically.

Resources are automatically released when pytest ends.

Resources are described in json file as array of objects. Each object has some mandatory fields but can contains any other as well. Required fields are: `id`, `online`, `hostname`.

## Example `resources.json`

```
[
  {
    "id": "1234",
    "online": true,
    "hostname": "localhost",
    "os": "Android"
  }
]
```

`id` should be unique for each resources. `online` describes if resource are available for allocator. Set this `false`  if you don't want to allocate resource. `hostname` is used to select suitable resource by running host. 

Usage:
```
pytest --allocation_hostname localhost -s --allocation_requirements os=Android my_test
```


## installation

**Requires:** python 3.7<

```python
pip install pytest-lockable
```


## integrations

pytest-lockable integrates pytest-metadata - when resource is 
reserved and [pytest-metadata](https://github.com/pytest-dev/pytest-metadata) plugin are in use metadata will 
be generated from resource json with  `resource_` -prefixes.
e.g. `resource_id=<id>`. 
Same dictionary are also recorded to testsuite property using
[record_testsuite_property](https://docs.pytest.org/en/stable/reference.html#record-testsuite-property) -method.

## Usage

Custom options:

```
--allocation_hostname=<hostname>, default=<os-hostname>  Allocation host
--allocation_requirements=<requirements>                 Resource requirements to be allocate
--allocation_timeout=<timeout>, default=10               Allocation timeout in seconds
--allocation_resource_list_file=<filename>, default=resources.json 
                                                         Available resorces list
--allocation_lock_folder=<folder>, default=<os-tmp-path> allocation lockfiles folder
```

*`<requirements>`* can be json-string or key-value pairs. requirements have to match available resources to make allocation possible. Key-value pairs example: `key=value&key2=value2` 

Example:

Use shared lockable resource
``` python
def test_example(lockable_resource):
    """ Simple test """
    print(f'Testing with resource: {lockable_resource}')
```

Allocate lockable resource during test with given requirements
``` python
def test_example(lockable):
    """ Simple test """
    with lockable.auto_lock({"my": "requirements"}) as allocation:
        print(f'Testing with resource#: {allocation.resource_id}')
```

See [example test](example/test_example.py). Usage:
```
cd example
pytest --allocation_hostname localhost -s --allocation_lock_folder . .
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jupe/pytest-lockable",
    "name": "pytest-lockable",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8, <4",
    "maintainer_email": "",
    "keywords": "py.test pytest lockable resource",
    "author": "Jussi Vatjus-Anttila",
    "author_email": "jussiva@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/44/26/b41927a73bf275a00358fde84f2b4b55fcceb57681db9f2c295f8006a86c/pytest-lockable-0.10.0.tar.gz",
    "platform": null,
    "description": "# pytest-lockable\n\n[![CircleCI](https://circleci.com/gh/jupe/pytest-lockable/tree/master.svg?style=svg)](https://circleci.com/gh/jupe/pytest-lockable/tree/master)\n[![PyPI version](https://badge.fury.io/py/pytest-lockable.svg)](https://pypi.org/project/pytest-lockable/)\n[![Coverage Status](https://coveralls.io/repos/github/jupe/pytest-lockable/badge.svg)](https://coveralls.io/github/jupe/pytest-lockable)\n\npytest plugin for lockable resources.\n\nReplacement for Jenkins lockable -plugin.\nLocking is implemented using `<resource-id>.pid` files and is released automatically.\n\nResources are automatically released when pytest ends.\n\nResources are described in json file as array of objects. Each object has some mandatory fields but can contains any other as well. Required fields are: `id`, `online`, `hostname`.\n\n## Example `resources.json`\n\n```\n[\n  {\n    \"id\": \"1234\",\n    \"online\": true,\n    \"hostname\": \"localhost\",\n    \"os\": \"Android\"\n  }\n]\n```\n\n`id` should be unique for each resources. `online` describes if resource are available for allocator. Set this `false`  if you don't want to allocate resource. `hostname` is used to select suitable resource by running host. \n\nUsage:\n```\npytest --allocation_hostname localhost -s --allocation_requirements os=Android my_test\n```\n\n\n## installation\n\n**Requires:** python 3.7<\n\n```python\npip install pytest-lockable\n```\n\n\n## integrations\n\npytest-lockable integrates pytest-metadata - when resource is \nreserved and [pytest-metadata](https://github.com/pytest-dev/pytest-metadata) plugin are in use metadata will \nbe generated from resource json with  `resource_` -prefixes.\ne.g. `resource_id=<id>`. \nSame dictionary are also recorded to testsuite property using\n[record_testsuite_property](https://docs.pytest.org/en/stable/reference.html#record-testsuite-property) -method.\n\n## Usage\n\nCustom options:\n\n```\n--allocation_hostname=<hostname>, default=<os-hostname>  Allocation host\n--allocation_requirements=<requirements>                 Resource requirements to be allocate\n--allocation_timeout=<timeout>, default=10               Allocation timeout in seconds\n--allocation_resource_list_file=<filename>, default=resources.json \n                                                         Available resorces list\n--allocation_lock_folder=<folder>, default=<os-tmp-path> allocation lockfiles folder\n```\n\n*`<requirements>`* can be json-string or key-value pairs. requirements have to match available resources to make allocation possible. Key-value pairs example: `key=value&key2=value2` \n\nExample:\n\nUse shared lockable resource\n``` python\ndef test_example(lockable_resource):\n    \"\"\" Simple test \"\"\"\n    print(f'Testing with resource: {lockable_resource}')\n```\n\nAllocate lockable resource during test with given requirements\n``` python\ndef test_example(lockable):\n    \"\"\" Simple test \"\"\"\n    with lockable.auto_lock({\"my\": \"requirements\"}) as allocation:\n        print(f'Testing with resource#: {allocation.resource_id}')\n```\n\nSee [example test](example/test_example.py). Usage:\n```\ncd example\npytest --allocation_hostname localhost -s --allocation_lock_folder . .\n```\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "lockable resource plugin for pytest",
    "version": "0.10.0",
    "project_urls": {
        "Bug Reports": "https://github.com/jupe/pytest-lockable",
        "Homepage": "https://github.com/jupe/pytest-lockable",
        "Source": "https://github.com/jupe/pytest-lockable/"
    },
    "split_keywords": [
        "py.test",
        "pytest",
        "lockable",
        "resource"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f02ddd7af6fb2781281cb6bbd730cd47adbcf870649e654067a86029769a4f2b",
                "md5": "234c3837c2c0f48ac95c26c8e32002c3",
                "sha256": "d80e073efb7708547c95a9c3816b1f25ff98d9ed37aa518412285945d8f2b217"
            },
            "downloads": -1,
            "filename": "pytest_lockable-0.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "234c3837c2c0f48ac95c26c8e32002c3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8, <4",
            "size": 4858,
            "upload_time": "2024-01-24T12:25:37",
            "upload_time_iso_8601": "2024-01-24T12:25:37.412394Z",
            "url": "https://files.pythonhosted.org/packages/f0/2d/dd7af6fb2781281cb6bbd730cd47adbcf870649e654067a86029769a4f2b/pytest_lockable-0.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4426b41927a73bf275a00358fde84f2b4b55fcceb57681db9f2c295f8006a86c",
                "md5": "ff102acf2ee5518b0b69c751f70e0572",
                "sha256": "b6f56fdd31c59f4860be7adb86ace547faab5c5b30ee58730e8eea2ee59ab875"
            },
            "downloads": -1,
            "filename": "pytest-lockable-0.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ff102acf2ee5518b0b69c751f70e0572",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8, <4",
            "size": 14096,
            "upload_time": "2024-01-24T12:25:38",
            "upload_time_iso_8601": "2024-01-24T12:25:38.485820Z",
            "url": "https://files.pythonhosted.org/packages/44/26/b41927a73bf275a00358fde84f2b4b55fcceb57681db9f2c295f8006a86c/pytest-lockable-0.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-24 12:25:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jupe",
    "github_project": "pytest-lockable",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "circle": true,
    "lcname": "pytest-lockable"
}
        
Elapsed time: 0.17205s