================
pytest-freezegun
================
.. image:: https://img.shields.io/pypi/v/pytest-freezegun.svg
:target: https://pypi.python.org/pypi/pytest-freezegun/
.. image:: https://travis-ci.org/ktosiek/pytest-freezegun.svg?branch=master
:target: https://travis-ci.org/ktosiek/pytest-freezegun
:alt: See Build Status on Travis CI
.. image:: https://ci.appveyor.com/api/projects/status/github/ktosiek/pytest-freezegun?branch=master&svg=true
:target: https://ci.appveyor.com/project/ktosiek/pytest-freezegun/branch/master
:alt: See Build Status on AppVeyor
Wrap tests with fixtures in freeze_time
Features
--------
* Freeze time in both the test and fixtures
* Access the freezer when you need it
Installation
------------
You can install "pytest-freezegun" via `pip`_ from `PyPI`_::
$ pip install pytest-freezegun
Usage
-----
Freeze time by using the ``freezer`` fixture::
def test_frozen_date(freezer):
now = datetime.now()
time.sleep(1)
later = datetime.now()
assert now == later
This can then be used to move time::
def test_moving_date(freezer):
now = datetime.now()
freezer.move_to('2017-05-20')
later = datetime.now()
assert now != later
You can also pass arguments to freezegun by using the ``freeze_time`` mark::
@pytest.mark.freeze_time('2017-05-21')
def test_current_date():
assert date.today() == date(2017, 5, 21)
The ``freezer`` fixture and ``freeze_time`` mark can be used together,
and they work with other fixtures::
@pytest.fixture
def current_date():
return date.today()
@pytest.mark.freeze_time
def test_changing_date(current_date, freezer):
freezer.move_to('2017-05-20')
assert current_date == date(2017, 5, 20)
freezer.move_to('2017-05-21')
assert current_date == date(2017, 5, 21)
They can also be used in class-based tests::
class TestDate:
@pytest.mark.freeze_time
def test_changing_date(self, current_date, freezer):
freezer.move_to('2017-05-20')
assert current_date == date(2017, 5, 20)
freezer.move_to('2017-05-21')
assert current_date == date(2017, 5, 21)
Contributing
------------
Contributions are very welcome.
Tests can be run with `tox`_.
You can later check coverage with `coverage combine && coverage html`.
Please try to keep coverage at least the same before you submit a pull request.
License
-------
Distributed under the terms of the `MIT`_ license, "pytest-freezegun" is free and open source software
Issues
------
If you encounter any problems, please `file an issue`_ along with a detailed description.
Credits
-------
This `Pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template.
.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter
.. _`@hackebrot`: https://github.com/hackebrot
.. _`MIT`: http://opensource.org/licenses/MIT
.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin
.. _`file an issue`: https://github.com/ktosiek/pytest-freezegun/issues
.. _`pytest`: https://github.com/pytest-dev/pytest
.. _`tox`: https://tox.readthedocs.io/en/latest/
.. _`pip`: https://pypi.python.org/pypi/pip/
.. _`PyPI`: https://pypi.python.org/pypi
Raw data
{
"_id": null,
"home_page": "https://github.com/ktosiek/pytest-freezegun",
"name": "pytest-freezegun",
"maintainer": "Tomasz Kontusz",
"docs_url": null,
"requires_python": "",
"maintainer_email": "tomasz.kontusz@gmail.com",
"keywords": "",
"author": "Tomasz Kontusz",
"author_email": "tomasz.kontusz@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f0/e3/c39d7c3d3afef5652f19323f3483267d7e6b0d9911c3867e10d6e2d3c9ae/pytest-freezegun-0.4.2.zip",
"platform": "",
"description": "================\npytest-freezegun\n================\n\n\n.. image:: https://img.shields.io/pypi/v/pytest-freezegun.svg\n :target: https://pypi.python.org/pypi/pytest-freezegun/\n\n.. image:: https://travis-ci.org/ktosiek/pytest-freezegun.svg?branch=master\n :target: https://travis-ci.org/ktosiek/pytest-freezegun\n :alt: See Build Status on Travis CI\n\n.. image:: https://ci.appveyor.com/api/projects/status/github/ktosiek/pytest-freezegun?branch=master&svg=true\n :target: https://ci.appveyor.com/project/ktosiek/pytest-freezegun/branch/master\n :alt: See Build Status on AppVeyor\n\nWrap tests with fixtures in freeze_time\n\n\nFeatures\n--------\n\n* Freeze time in both the test and fixtures\n* Access the freezer when you need it\n\n\nInstallation\n------------\n\nYou can install \"pytest-freezegun\" via `pip`_ from `PyPI`_::\n\n $ pip install pytest-freezegun\n\n\nUsage\n-----\n\nFreeze time by using the ``freezer`` fixture::\n\n def test_frozen_date(freezer):\n now = datetime.now()\n time.sleep(1)\n later = datetime.now()\n assert now == later\n\nThis can then be used to move time::\n\n def test_moving_date(freezer):\n now = datetime.now()\n freezer.move_to('2017-05-20')\n later = datetime.now()\n assert now != later\n\nYou can also pass arguments to freezegun by using the ``freeze_time`` mark::\n\n @pytest.mark.freeze_time('2017-05-21')\n def test_current_date():\n assert date.today() == date(2017, 5, 21)\n\nThe ``freezer`` fixture and ``freeze_time`` mark can be used together,\nand they work with other fixtures::\n\n @pytest.fixture\n def current_date():\n return date.today()\n\n @pytest.mark.freeze_time\n def test_changing_date(current_date, freezer):\n freezer.move_to('2017-05-20')\n assert current_date == date(2017, 5, 20)\n freezer.move_to('2017-05-21')\n assert current_date == date(2017, 5, 21)\n\nThey can also be used in class-based tests::\n\n class TestDate:\n\n @pytest.mark.freeze_time\n def test_changing_date(self, current_date, freezer):\n freezer.move_to('2017-05-20')\n assert current_date == date(2017, 5, 20)\n freezer.move_to('2017-05-21')\n assert current_date == date(2017, 5, 21)\n\n\nContributing\n------------\n\nContributions are very welcome.\nTests can be run with `tox`_.\nYou can later check coverage with `coverage combine && coverage html`.\nPlease try to keep coverage at least the same before you submit a pull request.\n\n\nLicense\n-------\n\nDistributed under the terms of the `MIT`_ license, \"pytest-freezegun\" is free and open source software\n\n\nIssues\n------\n\nIf you encounter any problems, please `file an issue`_ along with a detailed description.\n\n\nCredits\n-------\n\nThis `Pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `Cookiecutter-pytest-plugin`_ template.\n\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/ktosiek/pytest-freezegun/issues\n.. _`pytest`: https://github.com/pytest-dev/pytest\n.. _`tox`: https://tox.readthedocs.io/en/latest/\n.. _`pip`: https://pypi.python.org/pypi/pip/\n.. _`PyPI`: https://pypi.python.org/pypi\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Wrap tests with fixtures in freeze_time",
"version": "0.4.2",
"project_urls": {
"Homepage": "https://github.com/ktosiek/pytest-freezegun"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9e090bdd7d24b9d21453ad3364ae1efbd65082045bb6081b5fd5eade91a9b644",
"md5": "2011ef4ce8fea964e6ca9ef3b6c41d4f",
"sha256": "5318a6bfb8ba4b709c8471c94d0033113877b3ee02da5bfcd917c1889cde99a7"
},
"downloads": -1,
"filename": "pytest_freezegun-0.4.2-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "2011ef4ce8fea964e6ca9ef3b6c41d4f",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 4590,
"upload_time": "2020-07-19T17:50:02",
"upload_time_iso_8601": "2020-07-19T17:50:02.191091Z",
"url": "https://files.pythonhosted.org/packages/9e/09/0bdd7d24b9d21453ad3364ae1efbd65082045bb6081b5fd5eade91a9b644/pytest_freezegun-0.4.2-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f0e3c39d7c3d3afef5652f19323f3483267d7e6b0d9911c3867e10d6e2d3c9ae",
"md5": "ab9915f280a4e37fafc118af1311cc41",
"sha256": "19c82d5633751bf3ec92caa481fb5cffaac1787bd485f0df6436fd6242176949"
},
"downloads": -1,
"filename": "pytest-freezegun-0.4.2.zip",
"has_sig": false,
"md5_digest": "ab9915f280a4e37fafc118af1311cc41",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9059,
"upload_time": "2020-07-19T17:50:03",
"upload_time_iso_8601": "2020-07-19T17:50:03.678786Z",
"url": "https://files.pythonhosted.org/packages/f0/e3/c39d7c3d3afef5652f19323f3483267d7e6b0d9911c3867e10d6e2d3c9ae/pytest-freezegun-0.4.2.zip",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-07-19 17:50:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ktosiek",
"github_project": "pytest-freezegun",
"travis_ci": true,
"coveralls": true,
"github_actions": false,
"appveyor": true,
"tox": true,
"lcname": "pytest-freezegun"
}