在冻结时间内用夹具包装测试
pytest-freezegun的Python项目详细描述
=====
pytest冷冻枪
=====
图片::https://travis-ci.org/ktosiek/pytest-freezegun.svg?branch=master
:目标:https://travis ci.org/ktosiek/pytest freezegun
:alt:请参阅travis ci上的构建状态
…图片::https://ci.appveyor.com/api/projects/status/github/ktosiek/pytest-freezegun?分支=主&;svg=true
:target:https://ci.appveyor.com/project/ktosiek/pytest-freezegun/branch/master
:alt:see build status on appveyor
它的安装
代码块::python
@pytest.fixture
def current戥date():
return date time.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.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
contribution
----
贡献非常受欢迎。
可以使用“tox”运行测试。
以后可以使用“coverage combine&;&;coverage html`.
在提交请求之前,请尽量保持覆盖率至少相同。
详细说明。
credits
----
_` 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
。_`提交问题: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
pytest冷冻枪
=====
图片::https://travis-ci.org/ktosiek/pytest-freezegun.svg?branch=master
:目标:https://travis ci.org/ktosiek/pytest freezegun
:alt:请参阅travis ci上的构建状态
…图片::https://ci.appveyor.com/api/projects/status/github/ktosiek/pytest-freezegun?分支=主&;svg=true
:target:https://ci.appveyor.com/project/ktosiek/pytest-freezegun/branch/master
:alt:see build status on appveyor
它的安装
代码块::python
@pytest.fixture
def current戥date():
return date time.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.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
contribution
----
贡献非常受欢迎。
可以使用“tox”运行测试。
以后可以使用“coverage combine&;&;coverage html`.
在提交请求之前,请尽量保持覆盖率至少相同。
详细说明。
credits
----
_` 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
。_`提交问题: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