Skip to main content

Wrap tests with fixtures in freeze_time

Project description

See Build Status on Travis CI 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

All the features can be seen in this example:

@pytest.fixture
def current_date():
    return datetime.now().date()

@pytest.mark.freeze_time('2017-05-21')
def test_current_date(current_date):
    assert current_date == date(2017, 5, 21)

@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)

def test_not_using_marker(freezer):
    now = datetime.now()
    time.sleep(1)
    later = datetime.now()
    assert now == later

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-freezegun-0.3.0.post1.zip (8.3 kB view details)

Uploaded Source

Built Distribution

pytest_freezegun-0.3.0.post1-py2.py3-none-any.whl (4.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-freezegun-0.3.0.post1.zip.

File metadata

  • Download URL: pytest-freezegun-0.3.0.post1.zip
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7

File hashes

Hashes for pytest-freezegun-0.3.0.post1.zip
Algorithm Hash digest
SHA256 b86b13ef75959bedf4c32f1fd81fec66fa4502d9892e0ef6ad1717a34fe1560e
MD5 2bf9d50fa0c78d20c193e7ded635bc2f
BLAKE2b-256 71b949668fdd9bc2fc751d3621b4230a53fa347ec8f8cdf6cc144a98a7088194

See more details on using hashes here.

File details

Details for the file pytest_freezegun-0.3.0.post1-py2.py3-none-any.whl.

File metadata

  • Download URL: pytest_freezegun-0.3.0.post1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7

File hashes

Hashes for pytest_freezegun-0.3.0.post1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 94c370a2cd3db9692962522cb74525d908e669df7cb53a448e01bb47c21a8173
MD5 a94a0b7815ca6ef2d29715948408887f
BLAKE2b-256 5d41a95042f853852718ffebcaed2791aa03ae50f9722050b5ce801df635fc5a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page