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.2.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

pytest_freezegun-0.2.0-py2-none-any.whl (5.1 kB view details)

Uploaded Python 2

File details

Details for the file pytest-freezegun-0.2.0.tar.gz.

File metadata

File hashes

Hashes for pytest-freezegun-0.2.0.tar.gz
Algorithm Hash digest
SHA256 212c471cd519dcd74dca8dbd15670ef6d630b2016f5874d4c147b7128ccf9693
MD5 41eee769dcaa3fa9a64daf3a64161f00
BLAKE2b-256 6d09e2e9a1dfacee46d56105f78e0d1bae05162bf493793e501a3d0ccb695982

See more details on using hashes here.

File details

Details for the file pytest_freezegun-0.2.0-py2-none-any.whl.

File metadata

File hashes

Hashes for pytest_freezegun-0.2.0-py2-none-any.whl
Algorithm Hash digest
SHA256 101ddc1da1b478f4b75c64a3d82184e5df3061dbc13515eeaf1305efb0d5d8f7
MD5 9a7486976ad2ee25516241cc9fa30ee2
BLAKE2b-256 68005d7cac3169841fcdee9e39d0b39c5b241f3457b662ae85616f0281f8dc9b

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