{ "info": { "author": "Omar Kohl", "author_email": "omarkohl@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Pytest", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Testing" ], "description": "================\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&service=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\t: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 `tmpdir`_ 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 (`tmpdir`_) 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 *py.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 py.path object\n(`tmpdir`_) 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\nUsage\n-----\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 import os\n import pytest\n\n @pytest.mark.datafiles('/opt/big_files/film1.mp4')\n def test_fast_forward(datafiles):\n path = str(datafiles) # Convert from py.path object to path (str)\n assert len(os.listdir(path)) == 1\n assert os.path.isfile(os.path.join(path, 'film1.mp4'))\n #assert some_operation(os.path.join(path, 'film1.mp4')) == expected_result\n\n # Using py.path syntax\n assert len(datafiles.listdir()) == 1\n assert (datafiles / 'film1.mp4').check(file=1)\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 import os\n import pytest\n\n FIXTURE_DIR = os.path.join(\n os.path.dirname(os.path.realpath(__file__)),\n 'test_files',\n )\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_find_borders(datafiles):\n for img in datafiles.listdir():\n print(img)\n #assert process(img) == some_expected_value\n\n @pytest.mark.datafiles(\n os.path.join(FIXTURE_DIR, 'img4.jpg'),\n os.path.join(FIXTURE_DIR, 'img5.jpg'),\n )\n def test_brightness(datafiles):\n for img in datafiles.listdir():\n print(img)\n #assert process(img) == some_expected_value\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 import os\n import pytest\n\n FIXTURE_DIR = os.path.join(\n os.path.dirname(os.path.realpath(__file__)),\n 'test_files',\n )\n\n ALL_IMGS = 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 os.path.join(FIXTURE_DIR, 'img4.jpg'),\n os.path.join(FIXTURE_DIR, 'img5.jpg'),\n os.path.join(FIXTURE_DIR, 'img6.jpg'),\n os.path.join(FIXTURE_DIR, 'img7.jpg'),\n os.path.join(FIXTURE_DIR, 'img8.jpg'),\n )\n\n @ALL_IMGS\n def test_something1(datafiles):\n for img in datafiles.listdir():\n print(img)\n #assert process(img) == some_expected_value\n\n @ALL_IMGS\n def test_something2(datafiles):\n for img in datafiles.listdir():\n print(img)\n #assert process(img) == some_expected_value\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.. code-block:: python\n\n import os\n import pytest\n\n FIXTURE_DIR = os.path.join(\n os.path.dirname(os.path.realpath(__file__)),\n '_fixture_files',\n )\n\n @pytest.mark.datafiles(\n os.path.join(FIXTURE_DIR, 'dir1'),\n os.path.join(FIXTURE_DIR, 'dir2'),\n os.path.join(FIXTURE_DIR, 'dir3'),\n on_duplicate='ignore',\n )\n def test_dir_ignore(datafiles):\n # datafiles.listdir() will list fileA and fileB originally from dir1\n pass\n\n @pytest.mark.datafiles(\n os.path.join(FIXTURE_DIR, 'dir1'),\n os.path.join(FIXTURE_DIR, 'dir2'),\n os.path.join(FIXTURE_DIR, 'dir3'),\n on_duplicate='replace',\n )\n def test_dir_replace(datafiles):\n # datafiles.listdir() will list fileA and fileB originally from dir3\n pass\n\n @pytest.mark.datafiles(\n os.path.join(FIXTURE_DIR, 'dir1'),\n os.path.join(FIXTURE_DIR, 'dir2'),\n os.path.join(FIXTURE_DIR, 'dir3'),\n # on_duplicate='exception' is the default and does not need to be\n # specified\n )\n def test_dir_exception(datafiles):\n # An exception will be raised because of duplicate filename fileA\n pass\n\n @pytest.mark.datafiles(\n os.path.join(FIXTURE_DIR, 'dir1'),\n os.path.join(FIXTURE_DIR, 'dir2'),\n os.path.join(FIXTURE_DIR, 'dir3'),\n keep_top_dir=True,\n )\n def test_dir_keep_top_dir(datafiles):\n # datafiles.listdir() will list dir1, dir2 and dir3 (each containing\n # fileA and fileB)\n pass\n\nExample 5\n~~~~~~~~~\n\nYou can also use a py.path object instead of str paths.\n\n.. code-block:: python\n\n import os\n import py\n import pytest\n\n _dir = os.path.dirname(os.path.realpath(__file__))\n FIXTURE_DIR = py.path.local(_dir) / 'test_files'\n\n @pytest.mark.datafiles(\n FIXTURE_DIR / 'img1.jpg',\n FIXTURE_DIR / 'img2.jpg',\n FIXTURE_DIR / 'img3.jpg',\n )\n def test_fast_forward(datafiles):\n assert len(datafiles.listdir()) == 3\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 2.0\n git push --tags\n # Upload the package for final release\n twine upload dist/*\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://pytest.org/latest/contents.html\n.. _`tmpdir`: https://pytest.org/latest/tmpdir.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\n\n.. :changelog:\n\nChange Log\n----------\n\nAll notable changes to this project will be documented in this file.\nThis project adheres to `Semantic Versioning`_. The change log is\nformatted as suggested by `Keep a CHANGELOG`_.\n\n`Unreleased`_\n~~~~~~~~~~~~~\n\nAdded\nChanged\nDeprecated\nRemoved\nFixed\nSecurity\n\n`2.0`_\n~~~~~~\n\nAdded\n\n* Explicit support for Python 3.6 (no changes were necessary)\n\nRemoved\n\n* BREAKING CHANGE: Python 2.6 is no longer supported (because we rely on pytest\n >= 3.6)\n\nFixed\n\n* Use the new pytest mark API to fix MarkInfo warnings (`#2`_)\n* BREAKING CHANGE: Symlinks are now copied as links instead of copying the\n target they point to (`#1`_)\n\n`1.0`_\n~~~~~~\n\nChanged\n\n* Bump version to 1.0 to signal that the plugin is stable\n* Minor refactorization without repercussions for users\n* Only use regular 'paths' (str) instead of py.path objects in documentation\n examples because they were confusing to some people (unfamiliar with py.path)\n\n`0.2`_\n~~~~~~\n\nAdded\n\n* Support for directories\n* Option 'keep_top_dir' to keep the top level directory (instead of only\n copying its content). Possible values are: True, False (default)\n* Option 'on_duplicate' to specify what to do when duplicate files or\n directories are encountered. Possible values are: 'exception' (default),\n 'ignore', 'overwrite'\n\n`0.1`_\n~~~~~~\n\nAdded\n\n* Specify one or multiple files to be copied by decorating the test\n function\n\n\n.. _`Unreleased`: https://github.com/omarkohl/pytest-datafiles/compare/2.0...master\n.. _`2.0`: https://github.com/omarkohl/pytest-datafiles/compare/1.0...2.0\n.. _`1.0`: https://github.com/omarkohl/pytest-datafiles/compare/0.2...1.0\n.. _`0.2`: https://github.com/omarkohl/pytest-datafiles/compare/0.1...0.2\n.. _`0.1`: https://github.com/omarkohl/pytest-datafiles/compare/3c31b2c...0.1\n\n\n.. _`#1`: https://github.com/omarkohl/pytest-datafiles/issues/1\n.. _`#2`: https://github.com/omarkohl/pytest-datafiles/issues/2\n\n\n.. _`Semantic Versioning`: http://semver.org/\n.. _`Keep a CHANGELOG`: http://keepachangelog.com/\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/omarkohl/pytest-datafiles", "keywords": "pytest datafiles tmpdir", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pytest-datafiles", "package_url": "https://pypi.org/project/pytest-datafiles/", "platform": "", "project_url": "https://pypi.org/project/pytest-datafiles/", "project_urls": { "Homepage": "https://github.com/omarkohl/pytest-datafiles" }, "release_url": "https://pypi.org/project/pytest-datafiles/2.0/", "requires_dist": [ "py", "pytest (>=3.6)" ], "requires_python": "", "summary": "py.test plugin to create a 'tmpdir' containing predefined files/directories.", "version": "2.0" }, "last_serial": 4349109, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "20fd566115f5cc3685d599185cfd1625", "sha256": "ebfb9be005d095ba4877110270ceda5a1967409849833a7794cdddf989a0fe95" }, "downloads": -1, "filename": "pytest_datafiles-0.1-py2-none-any.whl", "has_sig": false, "md5_digest": "20fd566115f5cc3685d599185cfd1625", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 6903, "upload_time": "2015-08-01T21:45:13", "url": "https://files.pythonhosted.org/packages/a8/98/b0e27603b9a8a63020728253540ad3d763faeace7b8cd77afa67d36688ac/pytest_datafiles-0.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "93d8b57337aa24ac13aca35a390abe92", "sha256": "93162f63bc7125a99ceeb830fc75de678e3a67cfd26acb4a250b8e07a0290a0a" }, "downloads": -1, "filename": "pytest-datafiles-0.1.tar.gz", "has_sig": false, "md5_digest": "93d8b57337aa24ac13aca35a390abe92", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4948, "upload_time": "2015-08-01T21:44:54", "url": "https://files.pythonhosted.org/packages/9d/0e/9f4c0ca3951e71c36440ad74cf9780331fcbd910adb49454af78936c4d1d/pytest-datafiles-0.1.tar.gz" } ], "0.1.dev0": [ { "comment_text": "", "digests": { "md5": "fdae7289687b1a2eba69bbd224ca7e91", "sha256": "339f74a49fb1f5d8985edb1440bdf11b2fb20bd65dc54e59ba2fb0c72dd82aee" }, "downloads": -1, "filename": "pytest-datafiles-0.1.dev0.tar.gz", "has_sig": false, "md5_digest": "fdae7289687b1a2eba69bbd224ca7e91", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1588, "upload_time": "2015-07-28T12:28:03", "url": "https://files.pythonhosted.org/packages/ca/84/b026087c2ba24c8e7a4ee26009b1556b47ffb3d8d525dade4a94aaba6a74/pytest-datafiles-0.1.dev0.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "489dff9efba563fd818520e9550ee1c8", "sha256": "797def269706f10e28bb56f8de30015f665d43665c5bd29b148752c95a25f9ad" }, "downloads": -1, "filename": "pytest_datafiles-0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "489dff9efba563fd818520e9550ee1c8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9159, "upload_time": "2015-09-02T19:44:24", "url": "https://files.pythonhosted.org/packages/b4/ef/dca407dcf464c31ee8fb35050566ebfffe6356ecc3a38536d3dcc2ce9fde/pytest_datafiles-0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c4ef8cfed3f5ef48b1982854888fcaab", "sha256": "afbeed6a98a7bd376e1c2a10421a0752ee6104e5f078c9d591c65d62493bdf04" }, "downloads": -1, "filename": "pytest-datafiles-0.2.tar.gz", "has_sig": false, "md5_digest": "c4ef8cfed3f5ef48b1982854888fcaab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6699, "upload_time": "2015-09-02T19:44:11", "url": "https://files.pythonhosted.org/packages/7e/19/a6519fb041d5ba2f41de21adc9101d1f01f4d531e5dbf385f305539dd1eb/pytest-datafiles-0.2.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "1438d922b28d0a33bb61b0d179ba482d", "sha256": "f7b10ad81f0361e4bfa5206be6df1159701b466e60a9c88c616fc135248c0024" }, "downloads": -1, "filename": "pytest_datafiles-1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1438d922b28d0a33bb61b0d179ba482d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 29269, "upload_time": "2016-06-24T19:02:26", "url": "https://files.pythonhosted.org/packages/81/c9/0740b92c7f4c1c63b1636bdad254499e8f59ea60257f3e709f1d16af1742/pytest_datafiles-1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e18280eba114ce3edbb606b5f92c435e", "sha256": "bb6493c00e8cfb26e9a08f3cc6d5796ae1d168a5a3d09a0e31b3c65b5619a4f0" }, "downloads": -1, "filename": "pytest-datafiles-1.0.tar.gz", "has_sig": false, "md5_digest": "e18280eba114ce3edbb606b5f92c435e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7373, "upload_time": "2016-06-24T19:02:44", "url": "https://files.pythonhosted.org/packages/22/9b/bc99e1f5abc17d746e41b1fbfb2643268a75189fd7102eff2cd6f2ecc087/pytest-datafiles-1.0.tar.gz" } ], "2.0": [ { "comment_text": "", "digests": { "md5": "a9c596dd310ce2564facf8ec38808dc8", "sha256": "e349b6ad7bcca111f3677b7201d3ca81f93b5e09dcfae8ee2be2c3cae9f55bc7" }, "downloads": -1, "filename": "pytest_datafiles-2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a9c596dd310ce2564facf8ec38808dc8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11319, "upload_time": "2018-10-07T11:18:00", "url": "https://files.pythonhosted.org/packages/21/a2/7da7d04eeca8def8062480e6696570aefde1c378152d2da9d5f3870649fb/pytest_datafiles-2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fdb332b13e623b70ecee66584f48b594", "sha256": "143329cbb1dbbb07af24f88fa4668e2f59ce233696cf12c49fd1c98d1756dbf9" }, "downloads": -1, "filename": "pytest-datafiles-2.0.tar.gz", "has_sig": false, "md5_digest": "fdb332b13e623b70ecee66584f48b594", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8205, "upload_time": "2018-10-07T11:18:02", "url": "https://files.pythonhosted.org/packages/c0/37/80e34ae45909d5e4d69e15ab765170c7e37ee9de1a09097d3badd74bb072/pytest-datafiles-2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a9c596dd310ce2564facf8ec38808dc8", "sha256": "e349b6ad7bcca111f3677b7201d3ca81f93b5e09dcfae8ee2be2c3cae9f55bc7" }, "downloads": -1, "filename": "pytest_datafiles-2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a9c596dd310ce2564facf8ec38808dc8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11319, "upload_time": "2018-10-07T11:18:00", "url": "https://files.pythonhosted.org/packages/21/a2/7da7d04eeca8def8062480e6696570aefde1c378152d2da9d5f3870649fb/pytest_datafiles-2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fdb332b13e623b70ecee66584f48b594", "sha256": "143329cbb1dbbb07af24f88fa4668e2f59ce233696cf12c49fd1c98d1756dbf9" }, "downloads": -1, "filename": "pytest-datafiles-2.0.tar.gz", "has_sig": false, "md5_digest": "fdb332b13e623b70ecee66584f48b594", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8205, "upload_time": "2018-10-07T11:18:02", "url": "https://files.pythonhosted.org/packages/c0/37/80e34ae45909d5e4d69e15ab765170c7e37ee9de1a09097d3badd74bb072/pytest-datafiles-2.0.tar.gz" } ] }