{"id":17027632,"url":"https://github.com/omarkohl/pytest-datafiles","last_synced_at":"2026-01-04T17:13:07.550Z","repository":{"id":35530722,"uuid":"39801600","full_name":"omarkohl/pytest-datafiles","owner":"omarkohl","description":"pytest plugin to create a tmpdir containing a preconfigured set of files and/or directories.","archived":false,"fork":false,"pushed_at":"2023-11-09T19:51:20.000Z","size":149,"stargazers_count":102,"open_issues_count":3,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T16:13:06.522Z","etag":null,"topics":["pytest","pytest-plugin","python"],"latest_commit_sha":null,"homepage":"","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/omarkohl.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-27T22:48:05.000Z","updated_at":"2025-01-16T07:15:02.000Z","dependencies_parsed_at":"2024-06-18T18:14:16.566Z","dependency_job_id":"4f27bdb6-6899-4fec-b16e-508b5392b45b","html_url":"https://github.com/omarkohl/pytest-datafiles","commit_stats":{"total_commits":80,"total_committers":6,"mean_commits":"13.333333333333334","dds":"0.32499999999999996","last_synced_commit":"02969ca9998c0ed5a25be827c427a2ef8e7a8626"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omarkohl%2Fpytest-datafiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omarkohl%2Fpytest-datafiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omarkohl%2Fpytest-datafiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omarkohl%2Fpytest-datafiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omarkohl","download_url":"https://codeload.github.com/omarkohl/pytest-datafiles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247517921,"owners_count":20951719,"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":["pytest","pytest-plugin","python"],"created_at":"2024-10-14T07:49:12.046Z","updated_at":"2026-01-04T17:13:07.521Z","avatar_url":"https://github.com/omarkohl.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"================\npytest-datafiles\n================\n\n.. image:: https://img.shields.io/travis/omarkohl/pytest-datafiles.svg\n    :target: https://travis-ci.org/omarkohl/pytest-datafiles\n\n\n.. image:: https://coveralls.io/repos/omarkohl/pytest-datafiles/badge.svg?branch=master\u0026service=github\n    :target: https://coveralls.io/github/omarkohl/pytest-datafiles?branch=master\n\n\n.. image:: https://img.shields.io/pypi/v/pytest-datafiles.svg\n    :target: https://pypi.python.org/pypi/pytest-datafiles\n\n\n.. image:: https://codeclimate.com/github/omarkohl/pytest-datafiles/badges/gpa.svg\n    :target: https://codeclimate.com/github/omarkohl/pytest-datafiles\n    :alt: Code Climate\n\n\n`pytest`_ plugin to create a `tmp_path`_ containing a preconfigured set of\nfiles and/or directories.\n\n**Note about maintenance:** This project is maintained and bug reports or pull\nrequests will be addressed. There is little activity because it simply works and\nno changes are required.\n\nFeatures\n--------\n\nThis plugin allows you to specify one or several files/directories that are\ncopied to a temporary directory (`tmp_path`_) before the execution of the test.\nThis means the original files are not modified and every test runs on its own\nversion of the same files.\n\nFiles/directories can be specified either as *strings* or as *pathlib.Path* objects.\n\nTo take advantage of the *datafiles* fixture in a test function, add\n*datafiles* as one of the test function parameters (per usual with `pytest`_\nfixtures) and decorate the test function with *@pytest.mark.datafiles(file1,\nfile2, dir1, dir2, ...)*. See the examples below.\n\nThe *datafiles* variable in your test function is a pathlib.Path object\n(`tmp_path`_) where the copied files are located. Under Linux systems this\nwill most likely be some subdirectory of */tmp/*.\n\n\nOptions\n-------\n\nThe following options can be specified as keyword arguments (kwargs) to the\n*@pytest.mark.datafiles* decorator function:\n\n- **keep_top_dir:** For all parameters that represent directories, keep that\n  directory instead of only (recursively) copying its content. Possible values\n  are *True* or *False*. *False* is the default value.\n- **on_duplicate:** Specify the action to take when duplicate files/directories\n  are found. Possible values are: *exception*, *ignore* and *replace*. The\n  default value is *exception*.\n\n  - *exception:* An exception is raised instead of copying the duplicate\n    file/directory.\n  - *ignore:* The second (or subsequent) files/directories with the same name\n    as the first one are simply ignored (i.e., the first file/directory with the\n    duplicate name is kept).\n  - *replace:* The second (or subsequent) files/directories with the same name\n    replace the previous ones (i.e., the last file/directory with the duplicate\n    name is kept).\n\nSee below for some *examples*.\n\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    pip install pytest-datafiles\n\n\nUpgrade to 3.0\n--------------\n\nVersion 3 now uses `tmp_path`_, resulting in `pathlib.Path` objects\ninstead of `py.path`.\n\nYour tests may need to be adjusted. In `examples/example_upgradev3.py` you see some possible\nvariations.\n\n\nUsage\n-----\n\nThe full code with more details for the examples can be found in `examples/`.\n\nExample 1\n~~~~~~~~~\n\nOne possible use case is when you are running tests on very big files that are\nnot included or packaged with your tests. For example, your test files are\nlarge video files stored under */opt/big_files/* . You don't want your tests modifying\nthe original files, but the files are required by the tests. You can reference these\ndata files in your test method as follows:\n\n.. code-block:: python\n\n    # more details in `examples/example_1.py`\n\n    @pytest.mark.datafiles('/opt/big_files/film1.mp4')\n    def test_fast_forward(datafiles):\n        # ...\n\n\nExample 2\n~~~~~~~~~\n\nNow for another use case: let's say in the directory where your tests are located, you\nplace a directory named *test_files*. Here you have a lot of images you want to run tests\non. By using this plugin, you make sure the original files under *test_files* are not\nmodified by every test.\n\n.. code-block:: python\n\n    # more details in `examples/example_2.py`\n\n    @pytest.mark.datafiles(\n        FIXTURE_DIR / 'img1.jpg',\n        FIXTURE_DIR / 'img2.jpg',\n        FIXTURE_DIR / 'img3.jpg',\n    )\n    def test_find_borders(datafiles):\n        # ...\n\n\nExample 3\n~~~~~~~~~\n\nIf all (or many) of your tests rely on the same files it can be easier to\ndefine one decorator beforehand and apply it to every test like this example:\n\n.. code-block:: python\n\n    # more details in `examples/example_3.py`\n\n    ALL_IMGS = pytest.mark.datafiles(\n        FIXTURE_DIR / 'img1.jpg',\n        FIXTURE_DIR / 'img2.jpg',\n        FIXTURE_DIR / 'img3.jpg',\n    )\n\n    @ALL_IMGS\n    def test_something1(datafiles):\n        # ...\n\n\nExample 4\n~~~~~~~~~\n\nImagine you have 3 directories (*dir1*, *dir2*, *dir3*) each containing the files\n(*fileA* and *fileB*).\n\nThis example clarifies the options **on_duplicate** and **keep_top_dir**.\n\n\nExample 5\n~~~~~~~~~\n\nYou can also use a str paths.\n\n.. code-block:: python\n\n    # more details in `examples/example_5.py`\n\n    @pytest.mark.datafiles(\n        os.path.join(FIXTURE_DIR, 'img1.jpg'),\n        os.path.join(FIXTURE_DIR, 'img2.jpg'),\n        os.path.join(FIXTURE_DIR, 'img3.jpg'),\n    )\n    def test_str(datafiles):\n        # ...\n\n\nContributing\n------------\n\nContributions are very welcome. Tests can be run with `tox`_. Please\nensure the coverage stays at least the same before you submit a pull\nrequest.\n\nTo create and upload a new package first update the version number and then:\n\n.. code-block:: bash\n\n    pip3 install --user -U twine\n    make clean\n    make dist\n    twine upload --repository-url https://test.pypi.org/legacy/ dist/*\n    # Verify the package is usable\n    virtualenv -p python3 test-venv\n    test-venv/bin/pip install pytest\n    test-venv/bin/pip install --index-url https://test.pypi.org/simple/ pytest-datafiles\n    # Create some test_example.py (e.g. with one of the examples above)\n    test-venv/bin/pytest test_example.py\n    # Set the git tag for final release\n    git tag -a 3.0\n    git push --tags\n    # Upload the package for final release\n    twine upload dist/*\n\nFinally create a release on GitHub and add the packages from dist/* to it.\n\nOf course this will only work if you have the necessary PyPI credentials for\nthis package.\n\n\nLicense\n-------\n\nDistributed under the terms of the `MIT license`_, \"pytest-datafiles\" is\nfree and open source software.\n\n\nIssues\n------\n\nIf you encounter any problems, please `file an issue`_ along with a\ndetailed description.\n\n\nAcknowledgements\n----------------\n\nThanks to `@flub`_ for the idea to use `pytest`_ marks to solve the\nproblem this plugin is trying to solve.\n\nSome ideas to improve this project were taken from the `Cookiecutter`_\ntemplates `cookiecutter-pypackage`_ and `cookiecutter-pytest-plugin`_.\n\n\n.. _`pytest`: https://docs.pytest.org/en/latest/contents.html\n.. _`tmp_path`: https://docs.pytest.org/en/latest/how-to/tmp_path.html\n.. _`tox`: https://tox.readthedocs.org/en/latest/\n.. _`MIT License`: http://opensource.org/licenses/MIT\n.. _`file an issue`: https://github.com/omarkohl/pytest-datafiles/issues\n.. _`@flub`: https://github.com/flub\n.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter\n.. _`cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomarkohl%2Fpytest-datafiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomarkohl%2Fpytest-datafiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomarkohl%2Fpytest-datafiles/lists"}