pytest的竞争条件测试

pytest-race的Python项目详细描述


https://github.com/idlesign/pytest-race

https://img.shields.io/pypi/v/pytest-race.svghttps://img.shields.io/pypi/dm/pytest-race.svghttps://img.shields.io/pypi/l/pytest-race.svghttps://img.shields.io/coveralls/idlesign/pytest-race/master.svghttps://img.shields.io/travis/idlesign/pytest-race/master.svghttps://landscape.io/github/idlesign/pytest-race/master/landscape.svg?style=flat

说明

pytest的竞赛条件测试仪

引入start_race运行竞赛条件测试的fixture。

要求

  • Python2.7+,3.3+
  • Pytest 2.9.0+

用法

您可以在测试中使用start_race夹具,如下所示:

fromtimeimportsleepACCUMULATOR=0# This global var is race conditions prone.deftest_race(start_race):fromrandomimportrandintdefactual_test():globalACCUMULATORincrement=randint(1,10000)accumulator=ACCUMULATORsleep(1)# Simulate some lag.ACCUMULATOR+=increment# By that moment ACCUMULATOR should have been updated# by another thread. Let's try to prove it.# Using simple `assert` as usual for pytest.assertaccumulator+increment==ACCUMULATOR# Let's run `actual_test` in 2 threads.start_race(threads_num=2,target=actual_test)

start_race接受以下参数:

  • threads_num-要同时运行的线程数。
  • target-可在线程中运行的实际测试调用。

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

推荐PyPI第三方库


热门话题
java无法使用mainthread的上下文类加载器将web应用程序添加到@SpringBootApplication的内置Tomcat中   为什么Java递归调用不释放局部变量内存   java堆栈重设堆栈奇偶范围   java如何分组,然后使用java8流列出toMap   JavaEclipse在引导仪表板上展示了“安装本地云服务”如何解决这个问题?   java多个backpress跳过该活动   concat向流中添加两个Java8流或一个额外元素   java在ToolTipText上使用图标   调试java。jvisulavm中添加JMXConnection时的lang.SecurityException   java如何通过JavaFX中的单选按钮对最大可选复选框进行约束?   Spring引导上下文一直试图连接到JavaRMI服务器,但失败了   java Spring cache@cacheexecute匹配列表中的键?   java导出报告并使用JasperReports保存在某个位置   java发布构建失败   java在活动中隐藏特定视图   java定义由canvas2image生成的图像的属性,例如alt标记   java如何将POJO转换为JSON,反之亦然?