Wrap tests with fixtures in freeze_time
Project description
pytest-freezeblaster
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-freezeblaster" via pip from PyPI:
$ pip install pytest-freezeblaster
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)
Credits
All credits go to ktosiek.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_freezeblaster-2.0.2.tar.gz.
File metadata
- Download URL: pytest_freezeblaster-2.0.2.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4908e796f5b509170a40e620005734e96f8fe1948f64fbac74adadc694e8ecdb
|
|
| MD5 |
4bfa3e57a836b99651bb5a74549ace03
|
|
| BLAKE2b-256 |
835f0d009268b9f1d707618e206a1b63945e4bd0acd89762ed635bb3abcb5029
|
Provenance
The following attestation bundles were made for pytest_freezeblaster-2.0.2.tar.gz:
Publisher:
release.yml on jammymalina/pytest-freezeblaster
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_freezeblaster-2.0.2.tar.gz -
Subject digest:
4908e796f5b509170a40e620005734e96f8fe1948f64fbac74adadc694e8ecdb - Sigstore transparency entry: 170377092
- Sigstore integration time:
-
Permalink:
jammymalina/pytest-freezeblaster@ebe304940fdb937111582d3d9962ec5629182920 -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/jammymalina
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ebe304940fdb937111582d3d9962ec5629182920 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_freezeblaster-2.0.2-py3-none-any.whl.
File metadata
- Download URL: pytest_freezeblaster-2.0.2-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44ea3e008fdf317e13dbf55d1e12f4628f17361828c34814868f80dd7d39138e
|
|
| MD5 |
c095dcdb1ce39640cb4a20dd7041b89d
|
|
| BLAKE2b-256 |
a075661d38540f2c94ce56a5debfe5d54c22b5979facdb57d145c940fe35f904
|
Provenance
The following attestation bundles were made for pytest_freezeblaster-2.0.2-py3-none-any.whl:
Publisher:
release.yml on jammymalina/pytest-freezeblaster
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_freezeblaster-2.0.2-py3-none-any.whl -
Subject digest:
44ea3e008fdf317e13dbf55d1e12f4628f17361828c34814868f80dd7d39138e - Sigstore transparency entry: 170377094
- Sigstore integration time:
-
Permalink:
jammymalina/pytest-freezeblaster@ebe304940fdb937111582d3d9962ec5629182920 -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/jammymalina
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ebe304940fdb937111582d3d9962ec5629182920 -
Trigger Event:
release
-
Statement type: