在冻结时间内用夹具包装测试

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



欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android首选项相同getPreference()值的不同数据   字符串如何在Java中连接两个列表中的单词   安卓 Java Socket编程:检测客户端和服务器是否连接   使用JTextField的java无法将值转换为int   在java中,如何在不通过超级构造函数设置的情况下将消息设置为自定义异常类   用于标识属性值的java正则表达式模式   Android中的java不可见谷歌地图   java正确取消启动ExecutorService的JavaFX任务   在非活动java类中使用安卓的融合位置提供程序,并在主活动类中获取经度和纬度   spring为什么我的大摇大摆不能用springboot在java中工作?   java JSF(2.2)ViewScope在Weblogic 12.2.1.2和JDK 8上使用Spring 4.3.7(在Mac OS和Docker Oracle Linux环境上)   java如何用一个按钮提高计时器速度   java如何检查字符是否是元音?   注册表引用了不存在的Java运行时环境安装或运行时已损坏错误   来自ResultSet java的mysql getDateTime   maven LanguageTool Java API是否具有“无用”依赖关系?   twitter api身份验证的java Trycatch问题   java在Apache Struts 1.1中是否可以显式白名单?   安卓致命异常:主java。lang.RuntimeException:被问及未知片段