Package: pytest-resource-path
pytest-resource-pathProvides path for uniform access to test resources in isolated directoryFeaturesLet's isolate test resources from test codeThe test which use test resource is not so many.
If 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?pytest-resource-pathprovides path for uniform access to test resources in isolated directory.This pytest plugin assumes that test resource is placed undertestresourcesdirectory directly undertests. (Don't worry, you can customize these directory names bypytest.ini)tests/
+--some_test_package/|+--some_test_module.py
+--testresources/+--some_test_package/+--some_test_module/InstallationYou can install "pytest-resource-path" viapipfromPyPI:pip install pytest-resource-pathUsageBasicYou can use fixtureresource_pathwhich is pathlib.Path instance (absolte path).deftest_method(resource_path):text_test_resource=(resource_path/'test_resource.txt').read_text()When assume that abovetest_methodis intests/some_tests_package_some_test_module.py, you have to placetest_resource.txtfollowing directory:tests/
+--some_test_package/|+--some_test_module.py
+--testresources/+--some_test_package/+--some_test_module/+--test_method/+--test_resource.txtIf you want to omit directory per method, you can do:deftest_method(resource_path):text_test_resource=Path(f'{resource_path}.txt').read_text()Note that the class name is not used in the path since It felt redundant in design.Get path to test resources root directoryYou can use fixtureresource_path_rootwhich is pathlib.Path instance (absolte path) pointing totestresources.deftest_method(resource_path_root):text_test_resource=(resource_path_root/'test_resource.txt').read_text()tests/
+--some_test_package/|+--some_test_module.py
+--testresources/+--test_resource.txtThis fixture may be your help duaring migration period of directory structure.
Or, may be usiful to preapare common directory with some of tests.deftest_method(resource_path_root):text_test_resource=(resource_path_root/'common/test_resource.txt').read_text()tests/
+--some_test_package/|+--some_test_module.py
+--testresources/+--common/+--test_resource.txtHow to customize directory namesTo traverse directory structure, this plugin requires to fix directory names.By default:directoryrequires to be namedRoot directory of teststestsRoot directory of test resourcestestresourcesYou can customize these required names bypytest.iniEx:[pytest]resource-path.directory-name-tests=integrationtestsresource-path.directory-name-test-resources=dataAbove customize fits following directory strucure:integrationtests/
+--some_test_package/|+--some_test_module.py
+--data/+--some_test_package/+--some_test_module/LicenseDistributed under the terms of theMITlicense, "pytest-resource-path" is free and open source softwareIssuesIf you encounter any problems, pleasefile an issuealong with a detailed description.ContributingContributions are very welcome.
Please ensure the coverage at least stays the same before you submit a pull request.CreditsThispytestplugin was generated withCookiecutteralong with@hackebrot'scookiecutter-pytest-plugintemplate.