{"id":22746231,"url":"https://github.com/yukihiko-shinoda/pytest-resource-path","last_synced_at":"2025-04-14T10:21:54.962Z","repository":{"id":52294766,"uuid":"261375368","full_name":"yukihiko-shinoda/pytest-resource-path","owner":"yukihiko-shinoda","description":"Pytest plugin to provide path for uniform access to test resources.","archived":false,"fork":false,"pushed_at":"2021-05-01T04:32:23.000Z","size":82,"stargazers_count":7,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T23:33:02.272Z","etag":null,"topics":["file-path","file-system","filesystem","fixture","fixture-loader","fixture-loading","flamework","pytest","pytest-fixtures","pytest-plugin","python","python3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yukihiko-shinoda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-05T06:08:49.000Z","updated_at":"2025-02-22T23:49:58.000Z","dependencies_parsed_at":"2022-09-05T22:11:49.731Z","dependency_job_id":null,"html_url":"https://github.com/yukihiko-shinoda/pytest-resource-path","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihiko-shinoda%2Fpytest-resource-path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihiko-shinoda%2Fpytest-resource-path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihiko-shinoda%2Fpytest-resource-path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yukihiko-shinoda%2Fpytest-resource-path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yukihiko-shinoda","download_url":"https://codeload.github.com/yukihiko-shinoda/pytest-resource-path/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860030,"owners_count":21173349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file-path","file-system","filesystem","fixture","fixture-loader","fixture-loading","flamework","pytest","pytest-fixtures","pytest-plugin","python","python3"],"created_at":"2024-12-11T02:12:27.926Z","updated_at":"2025-04-14T10:21:54.936Z","avatar_url":"https://github.com/yukihiko-shinoda.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pytest-resource-path\n\n[![Test](https://github.com/yukihiko-shinoda/pytest-resource-path/workflows/Test/badge.svg)](https://github.com/yukihiko-shinoda/pytest-resource-path/actions?query=workflow%3ATest)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/a5160a2616238bad3349/test_coverage)](https://codeclimate.com/github/yukihiko-shinoda/pytest-resource-path/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/a5160a2616238bad3349/maintainability)](https://codeclimate.com/github/yukihiko-shinoda/pytest-resource-path/maintainability)\n[![Code Climate technical debt](https://img.shields.io/codeclimate/tech-debt/yukihiko-shinoda/pytest-resource-path)](https://codeclimate.com/github/yukihiko-shinoda/pytest-resource-path)\n[![Updates](https://pyup.io/repos/github/yukihiko-shinoda/pytest-resource-path/shield.svg)](https://pyup.io/repos/github/yukihiko-shinoda/pytest-resource-path/)\n[![Python versions](https://img.shields.io/pypi/pyversions/pytest-resource-path.svg)](https://pypi.org/project/pytest-resource-path)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/pytest-resource-path)](https://pypi.org/project/pytest-resource-path)\n[![Twitter URL](https://img.shields.io/twitter/url?style=social\u0026url=https%3A%2F%2Fgithub.com%2Fyukihiko-shinoda%2Fpytest-resource-path)](http://twitter.com/share?text=pytest-resource-path\u0026url=https://pypi.org/project/pytest-resource-path/\u0026hashtags=python)\n\nProvides path for uniform access to test resources in isolated directory\n\n## Features\n\n### Let's isolate test resources from test code\n\nThe test which use test resource is not so many.\nIf we place test resource with test code, these resources will fill the display area of explorer. Wouldn't it be more productive if the files or directories which is not related with almost tests wasn't usually displayed?\n\n**pytest-resource-path** provides path for uniform access to test resources in isolated directory.\n\nThis pytest plugin assumes that test resource is placed under `testresources` directory directly under `tests`. (Don't worry, you can customize these directory names by `pytest.ini`)\n\n```bash\ntests/\n+-- some_test_package/\n|   +-- some_test_module.py\n+-- testresources/\n    +-- some_test_package/\n        +-- some_test_module/\n```\n\n## Installation\n\nYou can install \"pytest-resource-path\" via [pip] from [PyPI]:\n\n```console\npip install pytest-resource-path\n```\n\n## Usage\n\n### Basic\n\nYou can use fixture `resource_path` which is pathlib.Path instance (**absolte path**).\n\n```python\ndef test_method(resource_path):\n    text_test_resource = (resource_path / 'test_resource.txt').read_text()\n```\n\nWhen assume that above `test_method` is in `tests/some_tests_package_some_test_module.py`, you have to place `test_resource.txt` following directory:\n\n```bash\ntests/\n+-- some_test_package/\n|   +-- some_test_module.py\n+-- testresources/\n    +-- some_test_package/\n        +-- some_test_module/\n            +-- test_method/\n                +-- test_resource.txt\n```\n\nIf you want to omit directory per method, you can do:\n\n```python\ndef test_method(resource_path):\n    text_test_resource = Path(f'{resource_path}.txt').read_text()\n```\n\nNote that the class name is not used in the path since It felt redundant in design.\n\n### Get path to test resources root directory\n\nYou can use fixture `resource_path_root` which is pathlib.Path instance (**absolte path**) pointing to `testresources`.\n\n```python\ndef test_method(resource_path_root):\n    text_test_resource = (resource_path_root / 'test_resource.txt').read_text()\n```\n\n```bash\ntests/\n+-- some_test_package/\n|   +-- some_test_module.py\n+-- testresources/\n    +-- test_resource.txt\n```\n\nThis fixture may be your help duaring migration period of directory structure.\nOr, may be usiful to preapare common directory with some of tests.\n\n```python\ndef test_method(resource_path_root):\n    text_test_resource = (resource_path_root / 'common/test_resource.txt').read_text()\n```\n\n```bash\ntests/\n+-- some_test_package/\n|   +-- some_test_module.py\n+-- testresources/\n    +-- common/\n        +-- test_resource.txt\n```\n\n### How to customize directory names\n\nTo traverse directory structure, this plugin requires to fix directory names.\n\nBy default:\n\ndirectory|requires to be named\n---|---\nRoot directory of tests|`tests`\nRoot directory of test resources|`testresources`\n\nYou can customize these required names by `pytest.ini`\n\nEx:\n\n```ini\n[pytest]\nresource-path.directory-name-tests = integrationtests\nresource-path.directory-name-test-resources = data\n```\n\nAbove customize fits following directory strucure:\n\n```bash\nintegrationtests/\n+-- some_test_package/\n|   +-- some_test_module.py\n+-- data/\n    +-- some_test_package/\n        +-- some_test_module/\n```\n\n## License\n\nDistributed under the terms of the [MIT] license, \"pytest-resource-path\" is free and open source software\n\n## Issues\n\nIf you encounter any problems, please [file an issue] along with a detailed description.\n\n## Contributing\n\nContributions are very welcome.\nPlease ensure the coverage at least stays the same before you submit a pull request.\n\n## Credits\n\nThis [pytest] plugin was generated with [Cookiecutter] along with [@hackebrot]'s [cookiecutter-pytest-plugin] template.\n\n[Cookiecutter]: https://github.com/audreyr/cookiecutter\n[@hackebrot]: https://github.com/hackebrot\n[MIT]: http://opensource.org/licenses/MIT\n[cookiecutter-pytest-plugin]: https://github.com/pytest-dev/cookiecutter-pytest-plugin\n[file an issue]: https://github.com/yukihiko-shinoda/pytest-resource-path/issues\n[pytest]: https://github.com/pytest-dev/pytest\n[pip]: https://pypi.org/project/pip/\n[PyPI]: https://pypi.org/project\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyukihiko-shinoda%2Fpytest-resource-path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyukihiko-shinoda%2Fpytest-resource-path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyukihiko-shinoda%2Fpytest-resource-path/lists"}